I have a number of webservices that all work. Typically, when i inspect a call in fiddler I will see something like the following;
POST /api/dosomeaction.php HTTP/1.1
Accept: application/json
Authorization: Basic BlahBlahBlah
Content-Type: application/json; charset=utf-8
Host: myhost.co.uk
Content-Length: 140
Expect: 100-continue
Connection: Keep-Alive
but when I try the same via html / ajax I get a different format of header captured. This is despite using the same authentication un/pwd.
Javascript is;
var hash = encodeBase64("username:password");
var request = new XMLHttpRequest();
var params = "ExtraData" + ":" + "foo";
request.open("POST", "http://www.myhost.co.uk/dosomeaction.php", false);
request.setRequestHeader("Content-type", "application/json");
request.setRequestHeader("Authorization", "Basic " + hash);
request.send(params);
And I get back
OPTIONS /dosomeaction.php HTTP/1.1
Accept: */*
Origin: http://localhost:2024
Access-Control-Request-Method: POST
Access-Control-Request-Headers: authorization
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: www.myhost.co.uk
Content-Length: 0
DNT: 1
Connection: Keep-Alive
Pragma: no-cache
When I inspect the call in Fiddler, the Auth tab says that no authorization data is present, and json / text is also empty. However the call is being made as the webserver is returning a 302 and directing me to a login page.
So my initial question is Why are authorization header and additional data not being sent?