Performs an HTTP Post, allowing a PowerBuilder application to send a request through CGI, NSAPI, or ISAPI.
Inet objects
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. |
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
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.
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 = "http://coltrane.sybase.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