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

简介: 因为要做移动梦网WAP的一些接口,所以要用到这种方式,接下来会有ASP.net版本的,这个是ASP版本的,利用了MSXML2.XMLHTTP对像。request.aspdim Https set Https=server.
因为要做移动梦网WAP的一些接口,所以要用到这种方式,接下来会有ASP.net版本的,这个是ASP版本的,利用了MSXML2.XMLHTTP对像。

request.asp

img_a6339ee3e57d1d52bc7d02b338e15a60.gif dim  Https 
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
set  Https = server.createobject( " MSXML2.XMLHTTP " )
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
' 定义一个XMLHTTP对像
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
Https.open  " POST " , " http://127.0.0.1/testpost/response.asp " , false
img_a6339ee3e57d1d52bc7d02b338e15a60.gifHttps.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> "
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
if  Https.readystate = 4   then
img_a6339ee3e57d1d52bc7d02b338e15a60.gifresponse.write 
" 提交成功 "
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
' readstate读取状态为4则成功,继续后面的,不成功当然就不用继续处理了
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
dim  objstream 
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
set  objstream  =  Server.CreateObject( " adodb.stream " )
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
' 定义一个stream,因为读过来的直接拿出来是乱码的,所以得处理一下
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
objstream.Type  =   1  
img_a6339ee3e57d1d52bc7d02b338e15a60.gifobjstream.Mode 
= 3  
img_a6339ee3e57d1d52bc7d02b338e15a60.gifobjstream.Open 
img_a6339ee3e57d1d52bc7d02b338e15a60.gifobjstream.Write Https.responseBody 
img_a6339ee3e57d1d52bc7d02b338e15a60.gifobjstream.Position 
=   0  
img_a6339ee3e57d1d52bc7d02b338e15a60.gifobjstream.Type 
=   2  
img_a6339ee3e57d1d52bc7d02b338e15a60.gifobjstream.Charset 
=   " GB2312 "  
img_a6339ee3e57d1d52bc7d02b338e15a60.gifhtml 
=  objstream.ReadText
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
' 转好码,就放到html里,好关闭这些对像
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
objstream.Close 
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
set  objstream  =   nothing  
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
set  https = nothing
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
end   if
img_a6339ee3e57d1d52bc7d02b338e15a60.gifresponse.write html


response.asp

img_a6339ee3e57d1d52bc7d02b338e15a60.gif ' 创建DOMDocument对象
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
Set  xml  =  Server.CreateObject ( " msxml2.DOMDocument " )
img_a6339ee3e57d1d52bc7d02b338e15a60.gifxml.async 
=   False
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
' 装载POST数据 
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
xml.Load Request 
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
If  xml.parseError.errorCode  <>   0   Then  
img_a6339ee3e57d1d52bc7d02b338e15a60.gif    response.write 
" 不能正确接收数据 "   &   " Description:  "   &  xml.parseError.reason  &   " <br>Line:  "   &  xml.parseError.Line
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
End   If
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
set  blogchild = xml.getElementsByTagName( " misc_command " )
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
' the_text=blogchild.item(0).childnodes(1).text
img_a6339ee3e57d1d52bc7d02b338e15a60.gif'
the_text=blogchild.item(0).text
img_a6339ee3e57d1d52bc7d02b338e15a60.gif'
for i=0 to blogchild.length-1
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
response.write the_text


利用这种方法,ASP里调用Servlet或Web Service都是很轻松的!
相关文章
|
1月前
|
XML 前端开发 数据格式
请描述如何使用`BeautifulSoup`或其他类似的库来解析 HTML 或 XML 数据。
【2月更文挑战第22天】【2月更文挑战第67篇】请描述如何使用`BeautifulSoup`或其他类似的库来解析 HTML 或 XML 数据。
|
2月前
|
XML 机器学习/深度学习 JSON
在火狐浏览器调ajax获取json数据时,控制台提示“XML 解析错误:格式不佳”。
在火狐浏览器调ajax获取json数据时,控制台提示“XML 解析错误:格式不佳”。
29 0
在火狐浏览器调ajax获取json数据时,控制台提示“XML 解析错误:格式不佳”。
|
30天前
|
Java 数据库连接 mybatis
Mybatis+mysql动态分页查询数据案例——Mybatis的配置文件(mybatis-config.xml)
Mybatis+mysql动态分页查询数据案例——Mybatis的配置文件(mybatis-config.xml)
19 1
|
30天前
Mybatis+mysql动态分页查询数据案例——配置映射文件(HouseDaoMapper.xml)
Mybatis+mysql动态分页查询数据案例——配置映射文件(HouseDaoMapper.xml)
15 1
|
6月前
|
XML 存储 JavaScript
【JavaSE专栏89】Java字符串和XML数据结构的转换,高效灵活转变数据
【JavaSE专栏89】Java字符串和XML数据结构的转换,高效灵活转变数据
|
2月前
|
SQL 开发框架 .NET
ASP.NET WEB+EntityFramework数据持久化——考核练习库——1、用户管理系统(考点:查询列表、增加、删除)
ASP.NET WEB+EntityFramework数据持久化——考核练习库——1、用户管理系统(考点:查询列表、增加、删除)
67 0
|
3月前
|
XML C# 数据格式
c# 追加 数据至xml文件
c# 追加 数据至xml文件
18 0
|
3月前
|
XML 存储 安全
Unity 数据读取|(五)XML文件解析(XmlDocument,XmlTextReader)
Unity 数据读取|(五)XML文件解析(XmlDocument,XmlTextReader)
|
4月前
|
XML C# 图形学
【Unity 3D】C#从XML中写入、读取、修改数据(附源码)
【Unity 3D】C#从XML中写入、读取、修改数据(附源码)
37 0
|
4月前
|
XML 存储 JSON
C# | DataGridView数据转存为Json、XML格式
DataGridView是常用的数据展示组件,而将其转存为Json或XML格式,则可以方便地进行数据的传输和存储。 Json格式具有轻量、易读、易解析等优点,广泛应用于Web开发、API接口传输等场景。 XML格式则具有良好的结构化特性,支持命名空间、数据类型等复杂数据表示方式,被广泛应用于数据交换、配置文件等领域。 因此,将DataGridView数据转存为Json、XML格式,不仅能够方便地进行数据的传输和存储,还能够满足不同场景下的数据需求。 本篇文章将介绍如何将DataGridView数据转存为Json、XML格式,并提供相应的代码示例。
98 0
C# | DataGridView数据转存为Json、XML格式