0
curl --basic --user {username}:{password} https://www.blueworkslive.com/api/Auth
我試圖寫這樣的東西,但它不會工作!我不斷收到錯誤400
將cURL API調用轉換爲Ajax
$.ajax({
url: "https://www.blueworkslive.com/api/Auth",
type: "GET", //This is what you should chage
dataType: "jsonp",
username: "admin", // Most SAP web services require credentials
password: "admin",
processData: false,
contentType: "application/json; charset=utf-8",
success: function() {
alert("success");
console.log("success");
},
error: function (xhr, ajaxOptions, thrownError) {
console.log("error");
console.log(xhr.responseText);
alert(xhr.status);
alert(xhr.responseText);
},
});
而這也: {$(文件)。就緒(函數(){VAR XHR =新的XMLHttpRequest();
xhr.open("GET", "https://www.blueworkslive.com/api/Auth?version=20091212", false);
xhr.setRequestHeader("Authorization", "Basic " + btoa("username.com:password"));
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Access-Control-Allow-Origin: *");
xhr.send("");
alert(xhr.status);
alert(xhr.responseText);
});} 錯誤:Access-Control-Allow-Origin不允許來源。我認爲錯誤是因我引起的從本地服務器上運行腳本(因爲原點設置爲默認爲空),所以我部署它的應用開發服務器上,以便我有一個公共origin.The的發生同樣的錯誤新的起源 - 即使現在的起源不再爲空,但服務器提供了起源!
@ blackpla9ue您是否在編輯時添加了評論? – devnull69
@ devnull69 nope。只有縮進。檢查編輯歷史。我嘗試期間 – blackpla9ue
有趣......要編輯我提交了「您的」編輯顯示添加註釋,現在我可以從歷史中看到,這種變化是 – devnull69