I'm currently working on setting up a POST request to a REST API (Cloudsight) with basic authorization. Here is the code I have so far:
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);
When I try to run it, I encounter the following error:
Uncaught SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Authorization:' is not a valid HTTP header field name.
If anyone has any insights into what might be wrong with the code, I would greatly appreciate it. I am new to JavaScript and APIs, and any help would be welcome. You can find Cloudsight's documentation here for reference: . I've searched through it but haven't been able to find other examples of Authorization HTTP Header in JavaScript.