I use the Chrome extension Postman to generate code for POST and GET requests with the appropiate headers, but after hours of working with this I see I'm gonna need help. It works perfectly in Postman, but the Javascript code it provides is somehow wrong.
If I make the request without the Authentication header I get a GET 401 - Unauthorized.
If I make the request with the Authentication header I get a OPTIONS 401 - Unauthorized.
$.ajax(
{
"async": true,
"crossDomain": true,
"url": "http://mywebservice.com/example.php?key=myValue",
"method": "GET",
"headers":
{
"authorization": "Basic YWRtaW39NjU1YzVlMWM="
}
})
Can anyone explain why I get a 401 Options when I use the correct Authorization header? I have also tried using btoa(username + ":" + password)
- same result.