我目前正在尝试使用基本授权设置对 REST API (Cloudsight) 的 POST 请求。到目前为止,我的代码是:
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://api.cloudsightapi.com/image_requests", true);
xhr.setRequestHeader("Authorization:", "CloudSight [key]");
xhr.setRequestHeader("Content-Type", "http://previews.123rf.com/images/valzann/valzann1412/valzann141200061/34262193-cigarette-end-on-a-white-background-Stock-Photo.jpg");
xhr.send(null);
console.log(xhr.status);
console.log(xhr.statusText);
当我尝试运行它时,我收到错误:Uncaught SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Authorization:' is not a valid HTTP header field name。
有谁知道代码有什么问题?我对 Javascript 和 API 很陌生,但非常感谢您的回答。(如果有帮助,这里是 Cloudsight 文档的链接:https ://cloudsight.readme.io我已经查看了它并试图找到其他 Authorization HTTP Header Javascript 示例但没有成功。)