我使用以下方法发出SOAP请求以登录服务器的API。当文件在尝试登录的服务器上时,它可以正常工作。当我尝试在不同的服务器上登录到相同的API时,我收到了404错误。
<% @ LANGUAGE = JavaScript %>
<% Response.CharSet="Utf-8" %>
<%
function makeSoapRequest( requestUrl, webServiceName, webMethodName, requestContent )
{
var xmlHttp = Server.CreateObject( "Msxml2.XMLHTTP.3.0" );
var request = '';
request += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
request += "<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/\">";
request += "<soap:Body><" + webMethodName +" xmlns=\"" + webServiceName + "\">";
request += requestContent;
request += "</" + webMethodName + "></soap:Body></soap:Envelope>";
var webServiceMethodName = webServiceName + "/" + webMethodName;
xmlHttp.open( "post", requestUrl, false );
xmlHttp.setRequestHeader( "Content-Type", "text/xml; charset=utf-8" );
xmlHttp.setRequestHeader( "Content-Length", request.length );
xmlHttp.setRequestHeader( "SOAPAction", webServiceMethodName );
xmlHttp.send( request );
responseText = xmlHttp.responsetext;
return responseText;
}
%>
为了测试它,我打印了requestUrl和request,并使用chrome addon Postman发送帖子请求并且它正常工作。
我的问题是,404是否因为将其发送到另一台服务器而被退回?我不认为情况会这样,但不是100%肯定。如果没有,为什么我会从代码执行中获得404,而不是邮递员请求?
答案 0 :(得分:0)
尝试将xmlHttp.open( "post", requestUrl, false );
更改为xmlHttp.open( "POST", requestUrl, false );