xml+atom 応答を返す Web サービスがいくつかあります。これらは、SAP NetWeaver Gateway アプリケーション サーバーでホストされます。それらにアクセスするには、BASIC 認証が必要です。応答には、CORS をサポートする次のヘッダーが含まれています。
access-control-allow-origin: *
access-control-allow-methods: POST, GET, OPTIONS, PUT, DELETE, HEAD
access-control-allow-headers: Content-Type
access-control-max-age: 1728000
以下のように、jquery を使用してサービスを呼び出す HTML5 アプリがあります。
var url = "http://mytesturl.com/test/";
$.ajax({
url: url,
async: true,
contentType:"application/atom+xml",
type: "GET",
crossdomain: true,
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', make_base_auth(uname, passwd));
}
})
.done(function( data, textStatus, jqXHR ){alert("success");})
.fail(function( jqXHR, textStatus, errorThrown ){
console.log(jqXHR.status);
alert(errorThrown + jqXHR.status);
});
サーバーの応答にヘッダーが含まれているにもかかわらず、次のような CORS エラーが引き続き発生します。
Failed to load resource: the server responded with a status of 401 (Unauthorized)
Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8383' is therefore not allowed access.
ユーザー名 (uname) とパスワード (passwd) が正しい。RestClient などのツールを使用してサービスを呼び出してみると、応答にヘッダーが含まれていることがわかります。Chrome バージョン 31.0 と Safari バージョン 6.0.5 でテストを試みました。何が欠けているのかわかりません。問題の解決に役立つ提案は素晴らしいでしょう。
ありがとう。