Ember アプリが別のサーバー上の API と通信できるように、CORS の実装に取り組んでいます。送信する必要がある要求は 2 つあります。POST による認証要求と、API エンドポイントの 1 つに対する GET 要求です。
どちらのリクエストもプリフライト リクエストを開始します。認証プリフライト リクエストは正常に実行されます。その後、API へのリクエストを実行すると、プリフライト リクエストがハングします。Chrome はステータスとタイプを「保留中」と表示し、リクエストは決して終了しません。
これが認証コードです。ここでは jQuery 1.10.2 を使用しています。
$.ajax({
type: 'POST',
url: 'https://blahblahblah.edu/AstraDev/Logon.ashx',
data: "{username: '', password: ''}",
contentType: 'text/json',
xhrFields: {
withCredentials: false
},
headers: {
},
success: function(response) {
console.log(response);
},
error: function(response) {
console.log(response);
}
});
そして、API GET リクエストの非常によく似たコード
$.ajax({
type: 'GET',
url: 'https://blahblahblah.edu/AstraDev/~api/query/room',
data: {fields: "Id"},
contentType: 'application/json; charset=utf-8',
xhrFields: {
withCredentials: true
},
headers: {
},
success: function(response) {
console.log(response)
},
error: function(response) {
console.log(response)
}
});
GET のコンテンツ タイプをプリフライトしないもの (「text/plain」など) に変更すると、リクエストは失敗します。しかし、プリフライトを行うと、プリフライトがハングします。
そして、これが関連するサーバー構成です。IIS 7.5 を使用しています。
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:8888" />
<add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
CORSは私にとってかなり新しいものです。だから多分私は明らかな何かを見逃しています。何か案は?ありがとう。