因为要做移动梦网wap的一些接口,所以要用到这种方式,接下来会有asp.net版本的,这个是asp版本的,利用了msxml2.xmlhttp对像。
request.asp
dim https
set https=server.createobject(“msxml2.xmlhttp”)
定义一个xmlhttp对像
https.open “post”,”http://127.0.0.1/testpost/response.asp”,false
https.send “<?xml version=””1.0″”?><misc_command version=””1.6″”><command_name>echo</command_name>
<command_data_block><sid>123456</sid><service_id>987654</service_id>
<sp_id>11111</sp_id><sp_password>22222</sp_password></command_data_block>
</misc_command>”
if https.readystate=4 then
response.write “提交成功”
readstate读取状态为4则成功,继续后面的,不成功当然就不用继续处理了
dim objstream
set objstream = server.createobject(“adodb.stream”)
定义一个stream,因为读过来的直接拿出来是乱码的,所以得处理一下
objstream.type = 1
objstream.mode =3
objstream.open
objstream.write https.responsebody
objstream.position = 0
objstream.type = 2
objstream.charset = “gb2312”
html = objstream.readtext
转好码,就放到html里,好关闭这些对像
objstream.close
set objstream = nothing
set https=nothing
end if
response.write html
response.asp
创建domdocument对象
set xml = server.createobject (“msxml2.domdocument”)
xml.async = false
装载post数据
xml.load request
if xml.parseerror.errorcode <> 0 then
response.write “不能正确接收数据” & “description: ” & xml.parseerror.reason & “<br>line: ” & xml.parseerror.line
end if
set blogchild=xml.getelementsbytagname(“misc_command”)
the_text=blogchild.item(0).childnodes(1).text
the_text=blogchild.item(0).text
for i=0 to blogchild.length-1
response.write the_text
利用这种方法,asp里调用servlet或web service都是很轻松的!