-
Notifications
You must be signed in to change notification settings - Fork 1
Description
I'm currently working on adding some cool Cablecast integrations features into our new website and I'm having trouble understanding how to send the Authentication header with my request. I'd appreciate it if I can just get a super quick example of sending that header and then carrying out an innocent action like perhaps "POST v1/digitalfiles/{id}/reindex" since any valid file will just get reindexed and be valid again.
Once that's out of the way, I'll be sure to merge my code here. We have some cool examples in the works. Thanks.
EDIT: I made a few new attempts using modified stuff from SO (let's not lie here) and reading the jQuery documentation. The code below (with username, pass, and IP obviously changed to correct values) gives me the following error:
"request header field is not allowed by access-control-allow-headers"
Ideas?
``var username = "plaintextUser";
var password = "plaintextPass";
function make_base_auth(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok);
return "Basic " + hash;
}
$.ajax
({
method: "POST", //use for jquery above 1.9.0 else type: 'POST'
url: "http://xxx.xxx.xxx.xxx/cablecastapi/v1/digitalfiles/867/reindex",
dataType: 'json',
async: false,
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', make_base_auth(username, password));
},
success: function (){
alert('The file is being reindexed!');
}
});
console.log("Testing connection.");