欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

利用ASP发送和接收XML数据的处理方法

程序员文章站 2022-07-02 18:23:53
request.asp dim https set https=server.createobject("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 " echo
123456 987654
11111 22222 "
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都是很轻松的!