最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP发送和接收XML数据的处理技巧

日期:11-11    来源:中国设计秀    作者:cnwebshow.com

  因为要做移动梦网WAP的一些接口,所以要用到这种方式,接下来会有asp.net版本的,这个是ASP版本的,利用了MSxml2.xmlhttp对像。Jbx中国设计秀

   request.aspJbx中国设计秀

dim Https Jbx中国设计秀
set Https=server.createobject("MSXML2.XMLHTTP")Jbx中国设计秀
'定义一个XMLHTTP对像Jbx中国设计秀
Https.open "POST","http://127.0.0.1/testpost/response.asp",falseJbx中国设计秀
Https.send "<?xml version=""1.0""?><misc_command version=""1.6""><command_name>echo</command_name>Jbx中国设计秀
<command_data_block><sid>123456</sid><service_id>987654</service_id>Jbx中国设计秀
<sp_id>11111</sp_id><sp_password>22222</sp_password></command_data_block>Jbx中国设计秀
</misc_command>"Jbx中国设计秀
if Https.readystate=4 thenJbx中国设计秀
 response.write "提交成功"Jbx中国设计秀
 'readstate读取状态为4则成功,继续后面的,不成功当然就不用继续处理了Jbx中国设计秀
 dim objstream Jbx中国设计秀
 set objstream = Server.CreateObject("adodb.stream")Jbx中国设计秀
 '定义一个stream,因为读过来的直接拿出来是乱码的,所以得处理一下Jbx中国设计秀
 objstream.Type = 1 Jbx中国设计秀
 objstream.Mode =3 Jbx中国设计秀
 objstream.Open Jbx中国设计秀
 objstream.Write Https.responseBody Jbx中国设计秀
 objstream.Position = 0 Jbx中国设计秀
 objstream.Type = 2 Jbx中国设计秀
 objstream.Charset = "GB2312" Jbx中国设计秀
 html = objstream.ReadTextJbx中国设计秀
 '转好码,就放到html里,好关闭这些对像Jbx中国设计秀
 objstream.Close Jbx中国设计秀
 set objstream = nothing Jbx中国设计秀
 set https=nothingJbx中国设计秀
end ifJbx中国设计秀
response.write htmlJbx中国设计秀

response.aspJbx中国设计秀

'创建DOMDocument对象Jbx中国设计秀
Set xml = Server.CreateObject ("msxml2.DOMDocument")Jbx中国设计秀
xml.async = FalseJbx中国设计秀

'装载POST数据 Jbx中国设计秀
xml.Load Request Jbx中国设计秀
If xml.parseError.errorCode <> 0 Then Jbx中国设计秀
 response.write "不能正确接收数据" & "Description: " & xml.parseError.reason & "<br>Line: " & xml.parseError.LineJbx中国设计秀
End IfJbx中国设计秀

set blogchild=xml.getElementsByTagName("misc_command")Jbx中国设计秀
'the_text=blogchild.item(0).childnodes(1).textJbx中国设计秀
'the_text=blogchild.item(0).textJbx中国设计秀
'for i=0 to blogchild.length-1Jbx中国设计秀
response.write the_textJbx中国设计秀

  利用这种方法,ASP里调用Servlet或Web Service都是很轻松的!Jbx中国设计秀

本文引用地址:/bc/article_46499.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明