7

我正在使用jQuery Fileupload上传文件。它没有发送标题,我设置到服务器。为什么授权头只在IE中丢失,但通过铬?jquery文件上传 - 不在IE9中发送标头

下面是代码:

upload_photo: function(){ 
    var url = '/api/v1/upload'; 
    $('#photoupload').fileupload({ 
     url: url, 
     dataType: 'json', 
     paramName: 'uploadFile', 
     beforeSend: function (xhr) { 
      setHeader(xhr); 
      $("#check_progress").html('true'); 
     },      
     done: function (e, responseJSON) { 
      var id = responseJSON.result.id; 
      url = responseJSON.result.url; 
      var photo_ids = $("#photo_ids"); 
      var val = photo_ids.val(); 
      photo_ids.val(val + id.toString() + ","); 
      $(".photothumb-wapper").append('<div class=\"photothumb\" id="post_photo_'+id+'"><div><img src=\"'+url+'\" /></div><img class=\"thumb-delete photo_delete\" id=\"'+id+'\" title=\"Remove\" src=\"/assets/delete-red.png\"></div>'); 
      $("#check_progress").html(""); 
     }, 
     start: function (e, data) { 
      $(".photothumb-wapper").append('<div class="photothumb photoprogress" style="border:none"><img src="/assets/ajax-loader.gif" /></div>'); 
     }, 
     always: function (e, data) { 
      $(".photoprogress").remove(); 
     } 
    }); 
} 

var setHeader = function (xhr) { 
    xhr.setRequestHeader('Authorization', 'Bearer fdf49c4f1cfgc176eb952f18eeefaec3e7'); 
}; 

集管在IE传递:

Request    : POST /api/v1/upload HTTP/1.1 
Accept    : text/html, application/xhtml+xml, \*/\* 
Referer    : url 
Accept-Language  : en-US 
User-Agent   :Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) 
Content-Type  :multipart/form-data; boundary=---------------------------7de2dfe037204f6 
Accept-Encoding  :gzip, deflate 
Host    :url 
Content-Length  :776595 
DNT     :1 
Connection   :Keep-Alive 
Cache-Control  :no-cache  
Cookie    :sitecookies 

接头在镀铬通过:

ResponseHeaders 
    date : Tue, 04 Mar 2014 07:32:20 GMT 
    Connection: Keep-Alive 
    content-length:225 
    content-type:application/json; charset=utf-8 
    cache-control:no-cache 
RequestHeaders 
    Accept: application/json, text/javascript, \*/\*; q=0.01 
    Authorization: Bearer fdf49c4f1cfgc176eb952f18eeefaec3e7 
    X-Requested-With: XMLHttpRequest 

为什么授权头在IE丢失?

+0

Dupilcate of http://stackoverflow.com/questions/7686827/how-can-i-add-a-custom-http-header-to-ajax-request-with-js-or-jquery –

+0

@Jibi - 不可以。手动传递标题不会有帮助。仍然授权没有通过在IE9中,因为它在IE10中正常工作,铬,FF –

回答

4

This回答我的问题,

与XHR文件上传支持设置自定义页眉只支持浏览器。

+1

为什么这个答案下来投票? –

+0

那么,你根本无法设置标题?你找到解决方法吗?我遇到了同样的问题:我们所有的请求都需要授权头文件来上传文件。 – darksoulsong

+0

不,我找不到任何解决方法 –

0

如旧的浏览器就像我们亲爱的IE浏览器的解决方法,你可以设置与认证令牌的cookie时对用户进行认证,然后把它在服务器和验证您验证头一个相同的方式。我知道这不是最优雅的解决方案,但它的工作原理。