PostURL

Description

Performs an HTTP Post, allowing a PowerBuilder application to send a request through CGI, NSAPI, or ISAPI.

Applies to

Inet objects

Syntax

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.


Return value

Integer. Returns values as follows:

1 -- Success

-1 -- General error

-2 -- Invalid URL

-4 -- Cannot connect to the Internet

-5 -- Unsupported secure (HTTPS) connection attempted

-6 -- Internet request failed

Usage

Call this function to invoke a CGI, NSAPI, or ISAPI function.

Data references a standard class user object that descends from InternetResult and that has an overridden InternetData function. This overridden function then performs the required processing with the returned HTML. Because the Internet returns data asynchronously, data must reference a variable that remains in scope after the function executes (such as a window-level instance variable).

To simulate a form submission, you need to send a header that indicates the proper Content-Type. For forms, the proper Content-Type header is:

Content-Type: application/x-www-form-urlencoded

For more information on the InternetResult standard class user object and the InternetData function, use the PowerBuilder Browser.

Timeout value for sending a request

The PostURL function relies on wininet.dll to post a request and returns -1 when the posting time exceeds the DLL timeout value. When you install Internet Explorer 7 or later, the default timeout value for this DLL is 30 seconds. Although it is possible to change the timeout value by configuring a ReceiveTimeOut registry key under HKEY_CURRENT_USER\ SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings, this is not recommended, since it can also affect the behavior of the Internet Explorer browser.

Examples

This example calls the PostURL function using server port 8080. Iinet is an instance variable of type inet:

Blob lblb_args
String ls_headers
String ls_url
Long ll_length
 
iir_msgbox = CREATE n_ir_msgbox
ls_url = "https://www.appeon.com/"
ls_url += "cgi-bin/pbcgi60.exe/"
ls_url += "myapp/n_cst_html/f_test?"
lblb_args = blob("")
ll_length = Len(lblb_args)
ls_headers = "Content-Length: " &
   + String(ll_length) + "~n~n"
iinet.PostURL &
   (ls_url, lblb_args, ls_headers, 8080, iir_msgbox)

This example shows the use of a header with the correct content-type for a form:

Blob lblb_args
String ls_headers
String ls_url
String ls_args
long ll_length
integer li_rc

li_rc = GetContextService( "Internet", iinet_base )
IF li_rc = 1 THEN   ir = CREATE n_ir   ls_url = "http://localhost/Site/testurl.stm?"
   ls_args = "user=MyName&pwd=MyPasswd"
   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 )
END IF

See also

GetURL

HyperLinkToURL

InternetData