我用VB编写了了Http发送程序,往Apache Tomcat发送请求,两种不同的发送方法,但是返回的结果确实不一样,因为需要设置超时,所以需要采用第二种方法来做,但是目前第二种方法未通过,恳请高人指点问题出处! XMLHTTP方式:
Set xmlsend = CreateObject("MSXML2.XMLHTTP")
xmlsend.open "post", "http://172.16.0.204:8010/B2EC/E2BServlet", False
xmlsend.setRequestHeader "Content-Type", "text/xml;charset=GB2312"
xmlsend.send (" <?xml version='1.0' encoding='GBK'?> <test> <sendtext> 测试 </sendtext> <test> ")
If xmlsend.Status = "200" Then
recstr = xmlsend.responseText
Else
erromsg = xmlsend.responseText
End If /*******************************发送内容格式:*****************************************************/
POST /B2EC/E2BServlet HTTP/1.0
Accept: */*
Accept-Language: zh-cn
Content-Type: text/xml;charset=GB2312
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.1)
Host: 127.0.0.1:8080
Content-Length: 370
Connection: Keep-Alive
Pragma: no-cache
Cookie: ASPSESSIONIDCABBARTD=JEBBDBPAPPFHJPADHCPJHCMK <?xml version='1.0' encoding='GBK'?> <test> <sendtext> 测试 </sendtext> <test> /*****************************返回正确信息,没有问题*************************************************/
ServerXMLHTTP方式:
Set xmlsend = CreateObject("MSXML2.ServerXMLHTTP")
xmlsend.setTimeouts 60000, 60000, 100000,100000
xmlsend.open "post", "http://172.16.0.204:8010/B2EC/E2BServlet", False
xmlsend.setRequestHeader "Content-Type", "text/xml;charset=GB2312"
xmlsend.send (" <?xml version='1.0' encoding='GBK'?> <test> <sendtext> 测试 </sendtext> <test> ")
If xmlsend.Status = "200" Then
recstr = xmlsend.responseText
Else
erromsg = xmlsend.responseText
End If /*******************************发送内容格式:**************************************************/
post /B2EC/E2BServlet HTTP/1.1
Content-Type: text/xml;charset=GB2312
Accept-Language: zh-cn
Content-Length: 370
Accept: */*
User-Agent: Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
Host: 127.0.0.1:8080
Connection: Keep-Alive <?xml version='1.0' encoding='GBK'?> <test> <sendtext> 测试 </sendtext> <test> /********************************返回错误信息:********************************************/ HTTP Status 501 - Method post is not defined in RFC 2068 and is not supported by the Servlet API -------------------------------------------------------------------------------- type Status report message Method post is not defined in RFC 2068 and is not supported by the Servlet API description The server does not support the functionality needed to fulfill this request (Method post is not defined in RFC 2068 and is not supported by the Servlet API ).
-------------------------------------------------------------------------------- Apache Tomcat/5.0.27
Set xmlsend = CreateObject("MSXML2.XMLHTTP")
xmlsend.open "post", "http://172.16.0.204:8010/B2EC/E2BServlet", False
xmlsend.setRequestHeader "Content-Type", "text/xml;charset=GB2312"
xmlsend.send (" <?xml version='1.0' encoding='GBK'?> <test> <sendtext> 测试 </sendtext> <test> ")
If xmlsend.Status = "200" Then
recstr = xmlsend.responseText
Else
erromsg = xmlsend.responseText
End If /*******************************发送内容格式:*****************************************************/
POST /B2EC/E2BServlet HTTP/1.0
Accept: */*
Accept-Language: zh-cn
Content-Type: text/xml;charset=GB2312
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.1)
Host: 127.0.0.1:8080
Content-Length: 370
Connection: Keep-Alive
Pragma: no-cache
Cookie: ASPSESSIONIDCABBARTD=JEBBDBPAPPFHJPADHCPJHCMK <?xml version='1.0' encoding='GBK'?> <test> <sendtext> 测试 </sendtext> <test> /*****************************返回正确信息,没有问题*************************************************/
ServerXMLHTTP方式:
Set xmlsend = CreateObject("MSXML2.ServerXMLHTTP")
xmlsend.setTimeouts 60000, 60000, 100000,100000
xmlsend.open "post", "http://172.16.0.204:8010/B2EC/E2BServlet", False
xmlsend.setRequestHeader "Content-Type", "text/xml;charset=GB2312"
xmlsend.send (" <?xml version='1.0' encoding='GBK'?> <test> <sendtext> 测试 </sendtext> <test> ")
If xmlsend.Status = "200" Then
recstr = xmlsend.responseText
Else
erromsg = xmlsend.responseText
End If /*******************************发送内容格式:**************************************************/
post /B2EC/E2BServlet HTTP/1.1
Content-Type: text/xml;charset=GB2312
Accept-Language: zh-cn
Content-Length: 370
Accept: */*
User-Agent: Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
Host: 127.0.0.1:8080
Connection: Keep-Alive <?xml version='1.0' encoding='GBK'?> <test> <sendtext> 测试 </sendtext> <test> /********************************返回错误信息:********************************************/ HTTP Status 501 - Method post is not defined in RFC 2068 and is not supported by the Servlet API -------------------------------------------------------------------------------- type Status report message Method post is not defined in RFC 2068 and is not supported by the Servlet API description The server does not support the functionality needed to fulfill this request (Method post is not defined in RFC 2068 and is not supported by the Servlet API ).
-------------------------------------------------------------------------------- Apache Tomcat/5.0.27
去java版问问