電話ギャップアプリケーションがあります。HTTP基本認証を必要とするRESTWebサービスにクエリを実行します
これが私のコードです:
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;
}
サーバー側から私が知っているのは、Android 4.xからクエリを実行すると、apacheが「ユーザーが資格情報なしでログインしようとしました」と表示することだけです。したがって、サーバーにデータが到着していないようですが、なぜですか?
不思議なことに、iPhone(iOS 4.1)とAndroidバージョン2.2および2.3で動作しますが、4.x(4.0.4および4.1)では動作しません。誰もが何かヒントを持っています、これは私を夢中にさせています。
編集:apacheアクセスログを調べることができました。Android4.xではすべてのリクエストで401が返され、2.2および2.3より前ではすべてのリクエストで200が返されます。ここですべてのHTTPリクエストヘッダーをログに記録して、何が到着するかを確認します。