PostURL PowerScript function
Description
Performs an HTTP Post, allowing a PowerBuilder application
to send a request through CGI, NSAPI, or ISAPI.
Controls
Inet objects
Syntax
|
1 |
<span>servicereference</span>.<span>PostURL</span> ( <span>urlname</span>, <span>urldata</span>, <span>headers</span>, {<span>serverport</span>, } <span>data</span> ) |
|
Argument |
Description |
|---|---|
|
servicereference |
Reference to the Internet service instance. |
|
urlname |
String specifying the URL to post. |
|
urldata |
Blob specifying arguments to the URL |
|
headers |
String specifying HTML headers. In Netscape, |
|
serverport |
Specifies the server port number for |
|
data |
InternetResult instance into which the |
Return Values
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:
|
1 |
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 SOFTWAREMicrosoftWindowsCurrentVersionInternet
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:
|
1 |
Blob lblb_args |
|
1 |
String ls_headers |
|
1 |
String ls_url |
|
1 |
Long ll_length |
|
1 |
|
1 |
iir_msgbox = CREATE n_ir_msgbox |
|
1 |
ls_url = "http://coltrane.sybase.com/" |
|
1 |
ls_url += "cgi-bin/pbcgi60.exe/" |
|
1 |
ls_url += "myapp/n_cst_html/f_test?" |
|
1 |
lblb_args = blob("") |
|
1 |
ll_length = Len(lblb_args) |
|
1 |
ls_headers = "Content-Length: " & |
|
1 |
   + String(ll_length) + "~n~n" |
|
1 |
iinet.<span>PostURL</span> & |
|
1 |
   (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:
|
1 |
Blob lblb_args<br>String ls_headers<br>String ls_url<br>String ls_args<br>long ll_length<br>integer li_rc<br> <br>li_rc = GetContextService( "Internet", iinet_base )<br>IF li_rc = 1 THEN<br>   ir = CREATE n_ir<br>   ls_url = "http://localhost/Site/testurl.stm?"<br>   ls_args = "user=MyName&pwd=MyPasswd"<br>   lblb_args = Blob( ls_args )<br>   ll_length = Len( lblb_args )<br>   ls_header = "Content-Type: " + &<br>      "application/x-www-form-urlencoded~n" + &<br>      "Content-Length: " + String( ll_length ) + "~n~n"<br>   li_rc = iinet.PostURL( ls_url, lblb_args, &<br>      ls_header, ir )<br>END IF |