6
看起來jQuery不會在POST
請求(或其他類型)之前發送OPTIONS
請求時沿Authorization
標頭髮送消息。我試圖達到的服務器返回了OPTIONS
請求的401狀態 - 我如何強制jQuery包含Authorization
標題,即使在這個初始請求中?jQuery.ajax不會發送帶有OPTIONS請求的授權標頭
$.ajax({
type: "POST",
url: url,
data: postData,
beforeSend: function ajaxBeforeSend(jqXHR) {
jqXHR.withCredentials = true;
jqXHR.setRequestHeader("Authorization", "Basic " + btoa(encodeURIComponent(escape($username.val())) + ":" + encodeURIComponent(escape($password.val()))));
},
success: runReportUrlCallback,
error: runReportErrorCallback
});
我也嘗試添加username
和password
到AJAX選項,但無濟於事。
可能的重複[爲什麼在Chrome瀏覽器中運行經過身份驗證的CORS請求的預檢OPTIONS請求,而不是Firefox?](http://stackoverflow.com/questions/15734031/why-does-the-preflight-options-request -of-an-authenticated-cors-request-in-in) – suish 2015-02-23 05:48:20
看起來像是讓服務器不需要對OPTIONS請求進行認證是修復它的唯一方法。 – suish 2015-02-23 05:49:54
我不「擁有」服務器。這是第三方網絡服務。 – 2015-02-23 05:52:24