利用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
投稿

猜你喜欢

  • 用Python制作mini翻译器的实现示例

    2021-07-26 02:48:09
  • Vuex简单入门

    2024-05-02 16:58:26
  • Pytest断言的具体使用

    2023-12-15 06:30:04
  • python制作图片缩略图

    2023-08-23 18:49:32
  • Sql Server中的非聚集索引详细介

    2024-01-26 15:57:56
  • Python + selenium自动化环境搭建的完整步骤

    2023-11-19 12:42:57
  • Python模块汇总(常用第三方库)

    2023-05-21 16:25:37
  • 详解Python下载图片并保存本地的两种方式

    2023-04-03 05:21:36
  • python socket多线程实现客户端与服务器连接

    2021-09-06 15:44:01
  • Python之web模板应用

    2021-06-27 10:13:47
  • python实现文件快照加密保护的方法

    2022-08-21 20:01:29
  • python gdal安装与简单使用

    2022-06-19 00:03:25
  • Centos 6.5系统下编译安装PHP 7.0.13的方法

    2023-06-07 13:04:26
  • 解决python -m pip install --upgrade pip 升级不成功问题

    2022-12-15 00:21:55
  • Go1.18新特性对泛型支持详解

    2024-05-22 17:46:25
  • 基于Python爬取股票数据过程详解

    2021-02-27 08:42:18
  • 深入理解golang的异常处理机制

    2024-02-04 10:02:37
  • form 元素内的字段 name 不要跟 form 属性名称一致

    2008-10-22 13:25:00
  • Python异常信息的不同展现方法总结

    2021-02-20 10:14:26
  • Python 3 使用Pillow生成漂亮的分形树图片

    2022-05-03 14:53:23
  • asp之家 网络编程 m.aspxhome.com