因此,我正在使用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明白,我会仔细看看它 –