pbfunc外部函数扩展应用-在Powerbuilder中进行Http的GET、POST操作
来源:互联网 发布:淘宝店铺首页装修尺寸 编辑:程序博客网 时间:2024/06/06 07:47
原文地址:http://www.cnblogs.com/wangxianjin/p/4908201.html
利用PBFunc扩展函数进行Http的操作时,需要对n_pbfunc_http的以下几个函数进行参数设置:
of_set_URL(...)//要进行GET或POST的url,必须of_set_ContentType(...)//设置Content-Type,可选of_post(...)、of_get(...)//根据需要选择post操作还是get操作如果需要utf-8编码转换的请用n_pbfunc_encode对象中的of_str2utf8函数
下面以http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?op=getCountryCityByIp这个来获取IP所在地的webservice来讲解GET和POST操作
- GET操作
在浏览器中输入http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?op=getCountryCityByIp,页面加载完后,在页面的HTTP GET里面中看到:
GET /WebServices/IpAddressSearchWebService.asmx/getCountryCityByIp?theIpAddress=string HTTP/1.1Host: www.webxml.com.cn
这就是我们需要调用的信息
我们只需要将Host附加到GET对应的/WebServices/....之前,并在最前面增加http://,调用代码如下:
1 n_pbfunc_http lnv_http 2 lnv_http.of_clear()//清空参数 3 4 n_pbfunc_encode lnv_encode 5 lnv_http.of_set_URL("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx/getCountryCityByIp?theIpAddress=136.213.185.177") 6 7 Blob lblb_data 8 string ls_error 9 IF lnv_http.of_Get(lblb_data,ls_error) Then10 string gbkData11 gbkData = lnv_encode.of_utf8ToGbk(lblb_data)//由于返回来的是utf-8编码,直接显示中文会乱码12 MessageBox("Http Get返回",gbkData)13 Else14 MessageBox("提示","执行失败")15 End IF
调用成功后返回
<?xml version="1.0" encoding="utf-8"?><ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml.com.cn/"> <string>136.213.185.177</string> <string>美国 </string></ArrayOfString>
- POST操作
同样道理,在页面的HTTP POST里面中看到:
POST /WebServices/IpAddressSearchWebService.asmx/getCountryCityByIp HTTP/1.1Host: www.webxml.com.cnContent-Type: application/x-www-form-urlencodedContent-Length: lengththeIpAddress=string
Content-Length,这个参数忽略,将Host附加到POST对应的/WebServices/....之前,并在最前面增加http://,调用of_set_ContentType来设置Content-Type,of_add_form设置theIpAddress的参数值,调用代码如下:
1 n_pbfunc_http lnv_http 2 lnv_http.of_clear()//清空参数 3 lnv_http.of_set_URL("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx/getCountryCityByIp") 4 lnv_http.of_set_ContentType("application/x-www-form-urlencoded") 5 6 n_pbfunc_encode lnv_encode 7 blob utf8 8 utf8= lnv_encode.of_str2utf8("136.213.185.177") 9 lnv_http.of_add_form("theIpAddress",utf8)10 11 Blob lblb_data12 string ls_error13 IF lnv_http.of_post(lblb_data,ls_error) Then14 15 string gbkData16 gbkData = lnv_encode.of_utf8ToGbk(lblb_data)//由于返回来的是utf-8编码,直接显示中文会乱码17 MessageBox("提示",gbkData)18 Else19 MessageBox("提示","执行失败")20 End IF
调用成功后返回的结果与GET一样,也可以使用该页面上面是SOAP操作,有兴趣的可以自行试验(参考下载demo中w_http中ws_*按钮代码)
Post的demo代码,参考w_http窗体
0 0
- pbfunc外部函数扩展应用-在Powerbuilder中进行Http的GET、POST操作
- pbfunc外部函数扩展应用-直接在Datawindow中生成QR二维码
- 利用PBfunc在Powerbuilder中使用https获取微信的AccessToken
- 利用PBfunc在Powerbuilder中使用https获取微信的AccessToken
- 利用PBFunc在Powerbuilder中解析Json对象
- SIM800A模块进行HTTP的GET和POST操作
- SendMessage API函数在PowerBuilder中应用
- SendMessage API函数在PowerBuilder中应用
- HTTP协议中POST、GET、HEAD的区别及应用
- 在java中http的get和post请求
- http中get与post的区别??
- http中get与post的区别
- HTTP中Get与Post的区别
- HTTP中Get与Post的区别
- HTTP中Get与Post的区别
- http中get和post的区别
- HTTP中Get与Post的区别
- HTTP中Get与Post的区别
- YARN ResourceManager调度器的分析以及文件压缩
- 一、iOS简介(及简述操作系统)
- PHP中的数组处理函数
- VC6.0的使用,工程的创建
- 创业感悟:对未来越有信心,对现在就越有耐心
- pbfunc外部函数扩展应用-在Powerbuilder中进行Http的GET、POST操作
- 软考系列——求最优算法盘点
- django 两种创建模型实例的方法
- [学习]用tarjian算法求强连通分量,tarjian算法缩点[学习知识~]
- Java 笔试:数据结构笔记
- Java 笔试:算法笔记
- Android 面试:常见问题总结
- iOS 【真机调试-免证书-开发者信任问题】
- mysql5.5