嗯,我找不到出路。我谷歌很多,尝试不同的方式,代码示例等等,我有这个奇怪的问题。 在SoapUI中,我可以测试Web服务,我甚至可以通过身份验证来测试服务。 但是... 我不能通过代码。AJAX + jQuery + SAP认证+基本认证= 401未经授权。 (代码+图片)
所以这里有一些打印屏幕和我正在尝试的代码。 如果你们能帮助我。 我将不胜感激。
谢谢。
CODE:---------------
var WEBSERVICE_URL = "http : // webservice:port/bla/bla/bla";
$.ajax({
url: WEBSERVICE_URL,
type: "POST",
dataType: "json",
username: "user",
password: "password",
processData: false,
crossDomain: true,
contentType: "application/json",
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic SomeLettersAndNumbers_I_GotBySoapUI_IKnowHereItGoesTheKeyString==");
},
success: function() {
alert("success");
},
error: function (xhr, ajaxOptions, thrownError) { //Add these parameters to display the required response
alert(xhr.status);
alert(xhr.responseText);
},
});