Pbfunc external function Extension application-GET, post operations for HTTP in PowerBuilder

Source: Internet
Author: User
Tags http post

When using the Pbfunc extension function for HTTP operation, the following functions of n_pbfunc_http need to be set for the parameters:

Of_set_url (...) // to make a GET or post URL, you must of_set_contenttype (...). )// set content-type, optional of_post (...), Of_get (...) // Select the post operation or get operation as needed if UTF-8 encoding conversion is required, use the Of_str2utf8 function in the N_pbfunc_encode object

The following http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?op= Getcountrycitybyip this to get the IP location of the webservice to explain get and post operations

    • Get operation

Enter Http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?op=getCountryCityByIp in the browser, after the page is loaded, In the page's HTTP GET inside see:

Get/webservices/ipaddresssearchwebservice.asmx/getcountrycitybyip?theipaddress=string HTTP/1.1Host: www.webxml.com.cn

That's the message we need to call.
We just need to attach the host to the get corresponding/webservices/.... Before, and at the top of the Add http://, the calling code reads

1 n_pbfunc_http lnv_http2Lnv_http.of_clear ()//Empty Parameters3 4 N_pbfunc_encode Lnv_encode5Lnv_http.of_set_url ("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx/getCountryCityByIp?theIpAddress= 136.213.185.177")6 7 Blob Lblb_data8 stringLs_error9 IF lnv_http.of_get (lblb_data,ls_error) ThenTen     stringGbkdata OneGbkdata = LNV_ENCODE.OF_UTF8TOGBK (lblb_data)//since the return is UTF-8 encoding, the direct display of Chinese will be garbled AMessageBox ("Http Get Return", Gbkdata) - Else -MessageBox ("Tips","Execution failed") theEnd IF

Return after successful invocation

<?XML version= "1.0" encoding= "Utf-8"?><arrayofstringXmlns: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>United States</string></arrayofstring>
    • Post operation

In the same way, you can see it in the HTTP post on the page:

Post/webservices/ipaddresssearchwebservice.asmx/getcountrycitybyip Http/1.1host:www.webxml.com.cncontent-type: Application/x-www-form-urlencodedcontent-length:lengththeipaddress=string

Content-length, this parameter is ignored, attaching host to post corresponding/webservices/.... Before, and at the top of the Add http://, call Of_set_contenttype to set the parameter value of the Content-type,of_add_form setting theipaddress, the calling code is as follows.

1 n_pbfunc_http lnv_http2Lnv_http.of_clear ()//Empty Parameters3Lnv_http.of_set_url ("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx/getCountryCityByIp")4Lnv_http.of_set_contenttype ("application/x-www-form-urlencoded")5 6 N_pbfunc_encode Lnv_encode7 blob UTF88Utf8= Lnv_encode.of_str2utf8 ("136.213.185.177")9Lnv_http.of_add_form ("theipaddress", UTF8)Ten  One Blob Lblb_data A stringLs_error - IF lnv_http.of_post (lblb_data,ls_error) Then -      the     stringGbkdata -Gbkdata = LNV_ENCODE.OF_UTF8TOGBK (lblb_data)//since the return is UTF-8 encoding, the direct display of Chinese will be garbled -MessageBox ("Tips", Gbkdata) - Else +MessageBox ("Tips","Execution failed") -End IF

The result returned after a successful call is the same as get, which can also be used for SOAP operations, which are interested in self-experimentation (refer to the Ws_* button code in w_http download demo)
Demo code for Post, refer to W_http form

Pbfunc external function Extension application-GET, post operations for HTTP in PowerBuilder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.