I have a phonegap application. I query a REST web service which requires HTTP Basic Authentication
here is my code:
var username = 'test';
var pass = 'test';
var string = username+':'+pass;
var hash = btoa(string);
$.ajax({
type: 'GET',
dataType: 'jsonp',
crossdomain: true,
//tried this
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', make_base_auth(username, pass));
},
//also this
username: 'test',
password: 'test',
//also this
data: {username: 'test', password: 'test'},
//and this
url: 'http://'+username+':'+pass+'@testserver.local/ProductService/getProductList.json?testQuery&_jsonp=availableProducts',
error: function (xhr, ajaxOptions, thrownError) {
console.warn(xhr.status);
console.warn(thrownError);
alert(xhr.status);
alert(thrownError);
}
});
function make_base_auth(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok);
alert("HASH: "+hash);
return "Basic " + hash;
}
All I know from the server side is that apache says "User attempted to log in with no credentials" when I query from Android 4.x. So it seems no data is arriving at the server, but why?
Strangely, it works on iPhone (iOS 4.1)and Android versions 2.2 and 2.3, but not on 4.x (4.0.4 and also 4.1). Anybody has any hints, this is driving me crazy.
EDIT: I was able to look into the apache access log, it returns a 401 on every request with Android 4.x, a 200 for every request with pre 2.2 and 2.3. I will log all HTTP Request Headers now to check what´s arriving.
No comments:
Post a Comment