How do I make a cross origin request to a web service that uses HTTP Basic Auth?
My client is developed in jQuery and my RESTful/JSON web service has been modified so "cross-origin" headers are returned.
Client code:
$.ajax({
url: "http://localhost:3000/applications", // external service
async: false,
beforeSend: function (req) {
req.setRequestHeader("Authorization", "Basic "+ base64_value)
},
success: function (applications) { $.each(applications, function(i, app) {
list.push(app)
})}
})
The client code triggers both a OPTIONS and GET request (in Chrome). The OPTIONS request fails with a 401.
What headers should I use for GET requests and what headers should I use for OPTIONS requests? And which server response headers should be used for GET and OPTIONS?
I made a request to the service using cURL and exact same authorization header and this worked (i.e. same username/password as in JavaScript code). So I guess this is related to the headers and OPTIONS method.