PB9.0 通过http协议以POST方式将XML发送到协议服务器
最近接触了银企互联系统,现在需要将生成的xml发送至服务器。
我查看了pb的帮助文件,posturl可以实现该功能,但是pb提供的例子我有点看不懂,
哪位大侠帮忙解释解释。最好有个实例对照。
servicereference.PostURL ( urlname, urldata, headers, {serverport, } data )
Argument Description
servicereference Reference to the Internet service instance.
urlname String specifying the URL to post.
urldata Blob specifying arguments to the URL specified by urlname.
headers String specifying HTML headers. In Netscape, a newline (~n) is required after
each HTTP header and a final newline after all headers.
serverport (optional) Specifies the server port number for the request. The default value
for this argument is 0, which means that the port number is determined by the system
(port 80 for HTTP requests).
data InternetResult instance into which the function returns HTML.
主要问题提就是那个headers是干嘛用的,data又是怎么回事?
工行的开发手册是这么说的
企业按照工行提供的xml包格式进行打包,在局域网内通过http协议以POST方式将交易包发送到NetSafe Client的安全http协议服务器。
http请求格式:action=”http://客户端NetSafe Client的地址和加密端口号/servlet/ICBCCMPAPIReqServlet?userID=证书ID&PackageID=包序列ID &SendTime=请求时间”
请求数据格式(post方式):Version=版本号(区分版本时间,暂定0.0.0.1) &TransCode=交易代码(区分交易类型,每个交易固定)&BankCode=客户的归属单位&GroupCIS=客户的归属编码&ID=客户的证书ID(无证书客户可空)&PackageID=客户的指令包序列号(由客户ERP系统产生,不可重复)&Cert=客户的证书公钥信息(进行BASE64编码;NC客户送空) &reqData=客户的xml请求数据
蓝字标出的部分应该是放到posturl参数的那一部分?
------解决方案--------------------------------------------------------用这种方式来发送数据
OLEObject dom, http
String Http_Name,result
Http_Name = "http://... "
dom = CREATE OLEObject
http = CREATE OLEObject
//messagebox调试看是否成功
messagebox( 'http ',http.ConnectToNewObject( "Msxml2.XMLHTTP "))
messagebox( 'dom ',dom.ConnectToNewObject( "Msxml2.DOMDocument "))
dom.Load( "c:\xxx.xml ")
http.Open( "POST ", Http_Name, TRUE)
http.Send(dom.xml)
do While http.readyState <> 4 // ' 查询状态,延时
yield()
Loop
result = http.responseText //这个测试用! 你可不写
messagebox( 'resul
tb ',result)
------解决方案--------------------------------------------------------Blob lblb_args
String ls_header
String ls_url
String ls_args
long ll_length
integer li_rc
inet iinet_base,iinet
//internetresult ir
iinet_base = create inet
iinet = create inet
li_rc = GetContextService( "Internet", iinet_base )
IF li_rc = 1 THEN
ir = CREATE n_cst_internet
ls_url = "http://xxx.com/getinfo.asp?"
ls_args = "var1=tr&var2=tttt&var3=&var4=r&var5=&var6=&var7=tttt&var8=&var9=&var10=ttt&var11="
lblb_args = Blob( ls_args )
ll_length = Len( lblb_args )
ls_header = "Content-Type: " + &
"application/x-www-form-urlencoded~n" + &
"Content-Length: " + String( ll_length ) + "~n~n"
li_rc = iinet.PostURL( ls_url, lblb_args, ls_header, ir )
messagebox('',string(li_rc))
END IF
integer li_filenum
li_filenum = fileopen('c:\1.html',textmode!,write!,shared!,replace!,encodingUTF8!)
filewriteex(li_filenum,ir.is_data)
fileclose(li_filenum)
ole_1.object.navigate('c:\1.html')
destroy iinet_base
destroy iinet
destroy ir
ir 建个internetresult的standard class n_interresult作为接收返回值