如何利用ASP发送和接收XML数据

huang   发表时间:2009-05-18 11:58:34   分类:建站知识   浏览( )   评论( )   收藏日志
添加到网摘:

ASP发送和接收XML数据的处理方法
利用到MSXML2.XMLHTTP对像
q966.asp

xml 代码
 
  1. dim Https 
  2. set Https=server.createobject("MSXML2.XMLHTTP")
  3. '定义一个XMLHTTP对像
  4. Https.open "POST","http://127.0.0.1/q966.asp",false
  5. Https.send "<?xml version=""1.0""?><misc_command version=""1.6""><command_name>echo</command_name>
  6. <command_data_block><sid>123456</sid><service_id>987654</service_id>
  7. <sp_id>11111</sp_id><sp_password>22222</sp_password></command_data_block></misc_command>"
  8. if Https.readystate=4 then
  9.  response.write "提交成功"
  10.  'readstate读取状态为4则成功,继续后面的,不成功当然就不用继续处理了
  11.  dim objstream 
  12.  set objstream = Server.CreateObject("adodb.stream")
  13.  '定义一个stream,因为读过来的直接拿出来是乱码的,所以得处理一下
  14.  objstream.Type = 1 
  15.  objstream.Mode =3 
  16.  objstream.Open 
  17.  objstream.Write Https.responseBody 
  18.  objstream.Position = 0 
  19.  objstream.Type = 2 
  20.  objstream.Charset = "GB2312" 
  21.  html = objstream.ReadText
  22.  '转好码,就放到html里,好关闭这些对像
  23.  objstream.Close 
  24.  set objstream = nothing 
  25.  set https=nothing
  26. end if
  27. response.write html
  28.  
  29. response.asp
  30.  
  31. '创建DOMDocument对象
  32. Set xml = Server.CreateObject ("msxml2.DOMDocument")
  33. xml.async = False
  34.  
  35. '装载POST数据 
  36. xml.Load Request 
  37. If xml.parseError.errorCode <> 0 Then 
  38.  response.write "不能正确接收数据" & "Description: " & xml.parseError.reason & "<br>Line: " & xml.parseError.Line
  39. End If
  40.  
  41. set blogchild=xml.getElementsByTagName("misc_command")
  42. 'the_text=blogchild.item(0).childnodes(1).text
  43. 'the_text=blogchild.item(0).text
  44. 'for i=0 to blogchild.length-1
  45. response.write the_text

利用以上方法,ASP里调用Servlet或Web Service都是很轻松的!

正在读取日志的评论数据,请稍后……
正在加载日志评论签写框,请稍后……
溜溜show会员登录
正在载入溜溜show会员登录...
溜溜show 日志归档
溜溜show 最新评论
{$SideComment}
溜溜show 最新留言
{$SideGB}
溜溜 阿里妈妈广告