因此,我正在使用Dropbox HTTP API與我的Angular2應用程序。我可以登錄,授權和使用list_folder
請求等,這一切都按預期工作。
但是,當我試圖執行一個簡單的POST請求files/download
我得到一個錯誤說我提供了一個非空content-type
:Angular2 HTTP - 提供非空HTTP內容類型頭* Safari *
Error in call to API function \"files/download\": You provided a non-empty HTTP \"Content-Type\" header (\"text/plain;charset=UTF-8\").
這是我當前的代碼 - 我已經嘗試了很多不同的方法我沒有在任何地方設置content-type
。
let headers = new Headers();
let url = 'https://content.dropboxapi.com/2/files/download';
headers.append('Authorization', `Bearer <inserted-bearer-here>`);
headers.append("Dropbox-API-Arg", "{\"path\": \"/Documents/code/convert.js\"}");
console.log(headers);
// this is an RxJS observable which is subscribed to later in my code...
return this.http.post(url, null, { headers: headers });
的content-type
是絕對不能設置,因爲我日誌標題到控制檯發送之前:
任何人都能夠闡明這個問題一些輕?我查看了其他關於SO的問題,只發現錯誤地設置了content-type
等字段,沒有設置它們的地方,它沒有工作。
- 編輯 -
此代碼工作正常在Chrome:
let headers = new Headers({
'Authorization': `Bearer ${this.userData.bearer}`,
'Dropbox-API-Arg': "{\"path\": \"/Documents/code/convert.js\"},
'content-type': null
});
http.post(url, null, { headers: headers })
.subsribe(...);
然而,在Safari看來,如果Content-Type
是null
它會自動追加text/plain;charset=UTF-8
我似乎無法找到強制發送空HTTP標頭的方法..如果有人知道這個問題的答案/或Safari的polyfill/fix,將是絕對驚人的!
我使用了你的代碼,並且在網絡標籤中查看實際的網絡請求,Dropbox API的HTTP請求確實有'Content-Type'頭文件集:Content-Type:text/plain; charset = UTF -8'。 Angular http庫顯然是在幕後設置的。 Dropbox API要求不要設置(因爲沒有要描述的主體),所以解決方法是找出停止Angular http庫的操作。不幸的是,我不知道如何反手。 – Greg
@Greg明白,我會仔細看看它 –