跨域访问header的问题

最近在服务器上要返回流数据到客户端,需要添加header,从而在客户端访问,但是访问时老是弹出“Refused to get unsafe header "*****"”问题,需要在iis的响应表头里加上



Access-Control-Expose-Headers:你的表头(Access-Control-Request-Headers:你的表头,可不加)。


另:附上传输流的代码:

服务器端:

   
    Public Sub getAttatchMents(ByVal url As String, ByVal oid As Integer)
        Dim ptask As System.Threading.Tasks.Task = System.Threading.Tasks.Task.Run(Async Function()
                                                                                       Await loadlll(url, oid)
                                                                                   End Function)
        ptask.Wait()
      
        If _attachMents.ContainsKey(oid) = False Then
            Return
        End If        
        For Each attach As MyAttachMentValue In _attachMents.Item(oid)
          
            Context.Response.AddHeader("Authorization", attach.name)
            Context.Response.BinaryWrite(attach.value)
            Context.Response.Flush()
        Next
      
    End Sub

客户端(通过arcgis js 访问):

esriRequest("http://localhost:88/EsriDataService.asmx/getAttatchMents",{
    responseType:"blob",
    method:"post",
    timeout:0,
    headers:{"Authorization":""},
    query:{
        "url":layer.url + "/" + layer.layerId,
        "oid":bh
    }
}).then(lang.hitch(this,this.showFile)).otherwise( function(error) {
    console.error("get Attachments failed. ", error);
});
showFile:function(response)
{
    var data = response.data;
   var header = response.getHeader("Authorization");
    blobToDataURL(data,lang.hitch(this, function (dataurl) { 
        var node = document.createElement("img");
        node.setAttribute("src",dataurl);
       // node.style.transform = "rotate(90deg)";
        node.style.width = "100%";
        node.style.height = "100%";
        this.ljcontent.appendChild(node);
     
    }));
    //**blob to dataURL**
    function blobToDataURL(blob, callback) {
        var a = new FileReader();
        a.onload = function (e) { callback(e.target.result); }
        a.readAsDataURL(blob);
    }
},


你可能感兴趣的:(arcgisweb开发)