现在的位置: 首页 > 综合 > 正文

asp中解析通过asp调用webservice 返回的xml

2013年01月07日 ⁄ 综合 ⁄ 共 1358字 ⁄ 字号 评论关闭

<% Set objHTTP = Server.CreateObject("MSXML2.XMLHTTP")

Set xmlDOC =Server.CreateObject("MSXML.DOMDocument")

strWebserviceURL = "http://localhost:8080/webservice/Service.asmx/sysLoginService" '编码的处理  Response.CodePage=65001  response.charset="utf-8"  

'设置参数和值 strRequest = "UserName="&server.urlencode("1中国")&"&SYSID=6&Password=21" objHTTP.Open "POST", strWebserviceURL, False '设置Content-Type很重要

 objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"

objHTTP.Send(strRequest) bOK = xmlDOC.load(objHTTP.responseXML) '查看状态值

 if objHTTP.Status=200 then Set oXMLRoot = xmlDOC.documentElement '// 获取节点  

 for i=0 to 2 text1 = oXMLRoot.childNodes.item(i).text Response.Write text1 next

text2 =oXMLRoot.selectSingleNode("UserName").text
Response.Write text2

'xmlStr = xmlDOC.xml 'xmlStr = Replace(xmlStr,"&lt;","<",1,-1,1) 'xmlStr = Replace(xmlStr,"&gt;",">",1,-1,1) 'Response.Write xmlStr  

 else

 Response.Write objHTTP.Statu&"<br>" Response.Write objHTTP.StatusText end if %>

附件返回的xml:

  <?xml version="1.0" ?>
- <map xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
  <LoginState>1</LoginState>
  <UserName>1中国</UserName>
  <RegistState>0</RegistState>
  </map>

 

红色的部分让我花了好多时间,原来送过去的时候asp默认的是用gb2312进行URLEncode,而。net是用utf-8,还有解析xml,这里就不用说了,花了好多的时间,都是直接载入xml文件的,但是和返回的xml文件其实是一样的!

参考文章:http://hi.baidu.com/westfruit/blog/item/01b8d0d7d8f17cd8a044df3d.html

【上篇】
【下篇】

抱歉!评论已关闭.