asp通过json调用webservice接口,并获取返回的xml数据及解析
2017-01-17 17:26
1041 查看
本事例是asp调用webservice接口,并获取返回的xml数据及解析!
<!--#include file="conn.asp"-->
<!--#include file ="md532.asp"-->
<!--#include file="SYS_INCLUDE_HTML.ASP"-->
<%
Response.Write "测试时间:"&now()&"<br>"
dim url,SOAPAction,HOST
url="http://192.168.17.71/KDWebservice/KDService.asmx?op=CreateCust"//webserbice地址 =号后面是接口的方法
Host="192.168.17.71"//ip地址
SOAPAction="http://tempuri.org/CreateCust"//把CreateCust替换你的方法
dim stringJS
custno=request("custno")
key="16394"
strtoken=custno&key
token=md5(strtoken,32,0)
//====获取单据表头信息
set rs=server.createobject("adodb.recordset")
sql ="select * from [customer] where custno='"&custno&"'"
rs.open sql,conn,1,1
if not rs.eof then
fCustNo=rs("custno")
fCustName=rs("cmingcheng")
end if
rs.close
stringJS="{'token':'"&token&"','head':{'fCustNo':'"&fCustNo&"','fCustName':'"&fCustName&"'}}"//这是我获取数据拼接的json ,可以替换你自己的json
Response.Write stringJS &"<br>"
SoapRequest="<?xml version="&CHR(34)&"1.0"&CHR(34)&" encoding="&CHR(34)&"utf-8"&CHR(34)&"?>"& _
"<soap:Envelope xmlns:xsi="&CHR(34)&"http://www.w3.org/2001/XMLSchema-instance"&CHR(34)&" "& _
"xmlns:xsd="&CHR(34)&"http://www.w3.org/2001/XMLSchema"&CHR(34)&" "& _
"xmlns:soap="&CHR(34)&"http://schemas.xmlsoap.org/soap/envelope/"&CHR(34)&">"& _
"<soap:Body>"& _
"<CreateCust xmlns="&CHR(34)&"http://tempuri.org/"&CHR(34)&">"& _//把CreateCust替换你的方法
"<json>"&stringJS&"</json>"& _
"</CreateCust>"& _//把CreateCust替换你的方法
"</soap:Body>"& _
"</soap:Envelope>"
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type","text/xml;charset=utf-8"
xmlhttp.setRequestHeader "HOST",Host
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.setRequestHeader "SOAPAction",SOAPAction
// ‘一定要与WEBSERVICE的命名空间相同,否则服务会拒绝
xmlhttp.Send(SoapRequest)
//‘这样就利用XMLHTTP成功发送了与SOAP示例所符的SOAP请求.
//‘检测一下是否成功:
Response.Write "Status:"&xmlhttp.Status&"<BR>"
Response.Write "StatusText:"&xmlhttp.StatusText&"<BR>"
if xmlhttp.status = 200 then
set xmldoc = server.createobject("msxml2.domdocument")
xmldoc.load(xmlhttp.responsexml)
//xmldoc是接收了webservice返回的xml内容,如果webservice返回的不是xml,就用xmlhttp.responsetext
objNodes = xmldoc.getElementsByTagName("root/msgType")
Response.Write "Status:"&objNodes &"<BR>"
sendMessageByPhone=xmldoc.documentElement.selectNodes("//root//msgType")(0).text //解析xml root 第一个节点 msgType 第二个节点
Response.Write "msgType:"&sendMessageByPhone&"<BR>"
sendMessageByPhone=xmldoc.documentElement.selectNodes("//root//msgstring")(0).text
Response.Write "msgstring:"&sendMessageByPhone&"<BR>"
else
Response.Write "调用webservice失败"
end if
Set xmlhttp = Nothing
%>
<!--#include file="conn.asp"-->
<!--#include file ="md532.asp"-->
<!--#include file="SYS_INCLUDE_HTML.ASP"-->
<%
Response.Write "测试时间:"&now()&"<br>"
dim url,SOAPAction,HOST
url="http://192.168.17.71/KDWebservice/KDService.asmx?op=CreateCust"//webserbice地址 =号后面是接口的方法
Host="192.168.17.71"//ip地址
SOAPAction="http://tempuri.org/CreateCust"//把CreateCust替换你的方法
dim stringJS
custno=request("custno")
key="16394"
strtoken=custno&key
token=md5(strtoken,32,0)
//====获取单据表头信息
set rs=server.createobject("adodb.recordset")
sql ="select * from [customer] where custno='"&custno&"'"
rs.open sql,conn,1,1
if not rs.eof then
fCustNo=rs("custno")
fCustName=rs("cmingcheng")
end if
rs.close
stringJS="{'token':'"&token&"','head':{'fCustNo':'"&fCustNo&"','fCustName':'"&fCustName&"'}}"//这是我获取数据拼接的json ,可以替换你自己的json
Response.Write stringJS &"<br>"
SoapRequest="<?xml version="&CHR(34)&"1.0"&CHR(34)&" encoding="&CHR(34)&"utf-8"&CHR(34)&"?>"& _
"<soap:Envelope xmlns:xsi="&CHR(34)&"http://www.w3.org/2001/XMLSchema-instance"&CHR(34)&" "& _
"xmlns:xsd="&CHR(34)&"http://www.w3.org/2001/XMLSchema"&CHR(34)&" "& _
"xmlns:soap="&CHR(34)&"http://schemas.xmlsoap.org/soap/envelope/"&CHR(34)&">"& _
"<soap:Body>"& _
"<CreateCust xmlns="&CHR(34)&"http://tempuri.org/"&CHR(34)&">"& _//把CreateCust替换你的方法
"<json>"&stringJS&"</json>"& _
"</CreateCust>"& _//把CreateCust替换你的方法
"</soap:Body>"& _
"</soap:Envelope>"
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type","text/xml;charset=utf-8"
xmlhttp.setRequestHeader "HOST",Host
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.setRequestHeader "SOAPAction",SOAPAction
// ‘一定要与WEBSERVICE的命名空间相同,否则服务会拒绝
xmlhttp.Send(SoapRequest)
//‘这样就利用XMLHTTP成功发送了与SOAP示例所符的SOAP请求.
//‘检测一下是否成功:
Response.Write "Status:"&xmlhttp.Status&"<BR>"
Response.Write "StatusText:"&xmlhttp.StatusText&"<BR>"
if xmlhttp.status = 200 then
set xmldoc = server.createobject("msxml2.domdocument")
xmldoc.load(xmlhttp.responsexml)
//xmldoc是接收了webservice返回的xml内容,如果webservice返回的不是xml,就用xmlhttp.responsetext
objNodes = xmldoc.getElementsByTagName("root/msgType")
Response.Write "Status:"&objNodes &"<BR>"
sendMessageByPhone=xmldoc.documentElement.selectNodes("//root//msgType")(0).text //解析xml root 第一个节点 msgType 第二个节点
Response.Write "msgType:"&sendMessageByPhone&"<BR>"
sendMessageByPhone=xmldoc.documentElement.selectNodes("//root//msgstring")(0).text
Response.Write "msgstring:"&sendMessageByPhone&"<BR>"
else
Response.Write "调用webservice失败"
end if
Set xmlhttp = Nothing
%>
相关文章推荐
- asp中解析通过asp调用webservice 返回的xml
- Asp.Net_Ajax调用WebService返回Json前台获取循环解析
- JAVA调用返回XML格式数据的WebService,并通过XPath解析XML的应用
- Java接收Cordys中webservice接口的返回数据并解析xml获取相应节点数据
- HTML5网页通过ajax跨域调用接口获取json数据并解析(一)
- Java数据接口编写简单例子,Java Json解析,服务端接口输出Json数据,客户端通过HTTP获取接口Json数据
- 通过servlet从气象局接口获取到天气预报的json数据,并解析得到的json数据存入数据库(案例)
- 【Android应用开发】-(17)获取Google天气预报通过Xml和JSON解析数据
- Android 获取Google Weather API 并通过Xml和JSON解析数据
- Android 获取Google Weather API 并通过Xml和JSON解析数据
- Java调用天气接口(百度天气)解析返回的JSON数据
- 通过soap请求webservice时,返回的数据是XML类型,有时候也需要解析本地的xml数据等,苹果自带类NSXMLParser解析xml还是很方便的,简单轻便
- java 调用wsdl接口同时将返回数据解析成json
- 通过HttpClient获取服务器接口json数据已及解析
- html中通过js获取接口JSON格式数据解析以及跨域问题
- 微信相关 -- 可以通过调用下面的方法 请求对应的url 获取微信服务器返回的json数据
- java 调用webservice 接口 解析返回json
- Jquery Easy UI 中的datagrid通过url调用webservice返回json数据
- 如何调用并解析调用远程接口返回的xml数据
- java通过url获取页面数据 java解析xml 基金净值接口使用方法