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.

Returns

Integer. Returns one of the following values:

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

Examples

Example 1

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)

Example 2

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