当我使用 Internet Explorer 调用任何 Sharepoint Web 服务时,浏览器会要求我提供凭据...但当我使用 Firefox 或 Chrome 时,我收到“401 未经授权”错误。
我正在编写一个 Firefox 扩展,因此我需要知道如何使用 JQuery 传递凭据......
$.ajax({
url: "http://sharepoint.xxxx.com/_vti_bin/search.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=utf-8"
});
$.ajax({
url: "http://sharepoint.xxxx.com/_vti_bin/lists.asmx",
beforeSend: function(xhr) {
xhr.setRequestHeader("SOAPAction",
"http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
},
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=utf-8"
});
最佳答案
您应该能够使用如下方式传递用户名/密码:
$.ajax({
url: "http://sharepoint.xxxx.com/_vti_bin/search.asmx",
type: "POST",
xhrFields: {
withCredentials: true
},
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=utf-8"
username: username,
password: password,
crossDomain: true
});
此调用使用 xhrFields withCredentials: true
并传递用户名和密码,允许您通过调用的其余部分发送这些项目。另外,请注意 crossDomain: true
用于告诉 jQuery 进行任何必要的更改以允许跨域调用。
关于JQUERY AJAX - 如何将凭据(用户和密码)传递给 Sharepoint Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8542886/