使用jQuery Ajax发送soap信封的自定义标头
我试图使用jQuery Ajax调用asmx服务。
POST /YderWS.asmx HTTP/1.1 Host: localhost Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://scandihealth.com/iwebservices/HentKommuner" string string string
以上是我需要发送给服务的SOAP 1.1请求。 我正在使用以下调用来设置自定义soap标头。 但我的请求失败了。 任何人都可以为我调试下面的代码,让我知道我需要做什么?
var authHeader = "SCTEST001 001 S"; //Call the page method $.ajax({ type: "GET", url: servicename + "/" + functionName, beforeSend: function (xhr) { xhr.setRequestHeader('AuthHeader', authHeader); }, success: successFn, error: errorFn });
编辑 * 如果需要其他信息来回答这个问题,请告诉我。 *
jQuery.ajax()
为任何类型的“Web服务”发出通用HTTP请求,而不仅仅是.NET Web服务。 您将要添加SOAPAction请求标头并将整个SOAP信封作为POST数据传递:
$.ajax({ type: 'POST', url: servicename + "/" + functionName, contentType: 'text/xml; charset=utf-8', headers: { SOAPAction: 'http://scandihealth.com/iwebservices/HentKommuner' }, data: 'string string string ', success: successFn, error: errorFn });
如果您使用的是jQuery <1.5,则需要使用beforeSend
来设置SOAPAction请求标头。
您可以在http://api.jquery.com/jQuery.ajax/找到jQuery.ajax()
的文档。
好像你错过了添加这些:
contentType: 'text/xml; charset=utf-8', dataType: 'xml'
添加这两行之后,我可以使用Selenium进行调试。