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

作者:佚名 时间:2009-02-02 08:57:00 

因为要做移动梦网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都是很轻松的!

标签:xml,XMLHTTP,数据,进口,asp
0
投稿

猜你喜欢

  • 优化你的ASP程序及优化网页

    2007-10-06 23:02:00
  • 带你深入了解SQL Server 2008的独到之处

    2009-01-07 14:20:00
  • 用CSS实现图片等比例缩放

    2008-01-18 21:10:00
  • 通过T-SQL语句实现数据库备份与还原的代码

    2011-12-01 08:02:15
  • 内容为空时提交如何处理

    2009-07-17 18:25:00
  • XML简易教程之一

    2008-09-05 17:19:00
  • ASP获取刚插入记录的自动编号ID

    2008-11-17 20:41:00
  • 解析:MySQL 数据库搜索中大小写敏感性

    2009-02-23 17:32:00
  • 解析ASP的Application和Session对象

    2007-09-14 10:13:00
  • delete from 表名与truncate table 表名区别

    2012-11-30 20:31:37
  • 怎样设置密码保护问题

    2009-02-16 13:12:00
  • 使用ACCESS做网络版程序的四种解决方案

    2009-01-14 16:22:00
  • Frontpage中网页字体的美化研究

    2008-03-10 12:13:00
  • 优化Oracle停机时间及数据库恢复

    2010-07-20 12:54:00
  • ActionScript3.0是革命性的

    2008-05-01 12:36:00
  • Oracle 子程序参数模式,IN,OUT,NOCOPY

    2009-10-23 18:08:00
  • 107条javascript(js)常用小技巧

    2007-10-30 12:40:00
  • 9个个人网站制作诀窍

    2007-12-13 11:36:00
  • Mootools 1.2教程(15)——滚动条(Slider)

    2008-12-09 17:35:00
  • 什么样的分页案例才是好的

    2007-11-23 19:08:00
  • asp之家 网络编程 m.aspxhome.com