2016-11-12 54 views
1

我一直在嘗試上傳表單數據,但我不想發送任何Content-Type標題。我已經嘗試設置發出http請求時刪除內容類型標題

headers: { 
      'X-Content-Type-Options': 'nosniff', 
      'Content-Type': undefined 
     } 

但是要求中仍包含

Content-Type:multipart/form-data; boundary=----WebKitFormBoundarykplXRCRn92v5Op52 

代碼塊以供參考:

$http({ 
    url: "/file/", 
    method: 'POST', 
    data: { 
     'file': res 
    }, 
    headers: { 
     'Content-Type': undefined 
    } 
}) 

我無法理解究竟發生了什麼。任何幫助將不勝感激。 PS:我明白什麼是多部分表格數據。我只需要去掉那個標題。

+0

如果使用Content-Type:'application/json; charset = UTF-8'或'Content-Type':'text/plain; charset = UTF-8',會發生什麼? AngularJS默認的Content-Type是application/json;當我將Content-Type設置爲undefined時,我的瀏覽器(Chrome)會插入'Content-Type:text/plain; charset = UTF-8 ' – georgeawg

+0

@georgeawg我試着將它設置爲'application/json',我發送多部分表單數據,它以某種方式更改標題。我懷疑它是否由瀏覽器完成。 – Shivi

回答