我有一個期望soap頭部並返回身份驗證令牌的Webservice。我設法使用jQuery將soap頭文件發佈到webservice。問題是如何使瀏覽器在每個Web服務授權請求上發送經過身份驗證的令牌。你的幫助將會很受歡迎。我用有用的鏈接如下: 參考:使用jQuery通過web服務進行SOAP身份驗證
代碼:
function logIn(username, password, token) {
var soapMessage =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<SecuredWebServiceHeader xmlns="http://tempuri.org/"> \
<Username>' + username + '</Username> \
<Password>' + password + '</Password> \
<AuthenticatedToken>' + token + '</AuthenticatedToken> \
</SecuredWebServiceHeader> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
url: "http://localhost/wstest/Service.asmx/AuthenticateUser",
type: "POST",
dataType: "xml",
data: soapMessage,
complete: endLogin,
contentType: "text/xml; charset=\"utf-8\""
});
return false;
}
function endLogin(xmlHttpRequest, status) {
alert(xmlHttpRequest.responseXML)
}