Post (HttpRequest function): Difference between revisions
m (1 revision) |
m (misc cleanup) |
||
(15 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{Template:HttpRequest:Post subtitle}} | {{Template:HttpRequest:Post subtitle}} | ||
The <var>Post</var> method sends an HTTP request to an HTTP server in the HTTP Post format: the request syntax sent to the server is the same as if a <code>METHOD="POST"</code> HTML form was submitted from a web browser. | |||
For more information about the HTTP POST request format, and for information about the HTTP protocol, refer to http://www.w3.org/Protocols/rfc2616/rfc2616.html. | |||
==Syntax== | ==Syntax== | ||
{{Template:HttpRequest:Post syntax}} | {{Template:HttpRequest:Post syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>% | <tr><th>%httpResponse</th> | ||
<td>A reference to the HTTPResponse object instantiated and returned by this Post method. | <td>A reference to the <var>[[HttpResponse_class|HTTPResponse]]</var> object instantiated and returned by this <var>Post</var> method. | ||
</td></tr> | </td></tr> | ||
<tr><th> | |||
<tr><th>httpRequest</th> | |||
<td>An instantiated <var>HttpRequest</var> object that contains the request (its methods were used to create the request). | <td>An instantiated <var>HttpRequest</var> object that contains the request (its methods were used to create the request). | ||
</td></tr> | </td></tr> | ||
<tr><th><var>Port | |||
<td>A string expression that identifies a previously defined | <tr><th><var>Port</var></th> | ||
This | <td>A string expression that identifies a previously defined <var>CLSOCK</var> port. The <var class="term">string</var> default is the <var>[[MASTER]]</var> port, if any is defined. However, if you omit <var class="term">string</var> and no <var>MASTER</var> port is defined, the request is canceled. | ||
<p> | |||
This is an optional and [[Notation conventions for methods#Named parameters|name-allowed]] parameter. If you specify a value, you may (but don't have to) specify the parameter name, <var>Port</var> (case not important). </p></td></tr> | |||
<tr><th><var>Cancel</var></th> | |||
<td>A numeric expression that controls whether the request is cancelled if a communication/socket error occurs. If zero, the request is not cancelled on these errors. If non-zero, the request is cancelled (though a message is still issued). If not specified, it defaults to 1 (cancel). See "Usage notes," below, for further discussion of error handling. | |||
This is an optional and name-allowed parameter. If you specify a value, you may (but don't have to) specify the parameter name, <var>Cancel</var> (case not important) if you want. | |||
<tr><th><var>CertificateCheck</var></th> | |||
<td>This optional ([[Notation conventions for methods#Named parameters|name required]]) argument invokes an SSL certificate request from the server at the time of the method call. | |||
The argument value (<var class="term">certificateChecker</var>) must be a function, presumably [[Local and Common entities#Defining and invoking a local method|local]], with this [[Method variables#Method template in method variable declaration|method template]]: | |||
<p class="syntax"><span class="literal">Function (String):</span><span class="term">methname</span> <span class="literal">Is Boolean</span> </p> | |||
<p> | |||
When a connection is established, the passed function is called with the certificate (binary, ASN.1 encoded, content copied to a <var>Longstring</var>) as its method object. </p> | |||
<ul> | |||
<li>If the function returns a <code>True</code>, the request is completed. </li> | |||
<li>If the function returns a <code>False</code>, the connection is closed and <var>HttpRequest</var> returns a null. | |||
In this case, the request is canceled unless the <var>Cancel</var> argument setting prevents it. </li> | |||
</ul> | |||
<p> | |||
For a <var>CertificateCheck</var> function example, see [[Get_(HttpRequest_function)#Examples|Examples]] for the <var>Get</var> method. </p></td></tr> | |||
<tr><th><var>CheckKeepAliveCertificate</var></th> | |||
<td>This optional, name required, argument controls how frequently a specified <var>CertificateCheck</var> function is invoked for a an HTTP [[HTTP Helper#Keep-Alive support|keep-alive]] connection. If <code>False</code>, the default, the <var class="term">certificateChecker</var> function is called only when the physical connection is first established and not for every HTTP request on that connection. If set to <code>True</code>, the <var>CertificateCheck</var> method is called for every request, keep-alive or not. | |||
</td></tr> | </td></tr> | ||
</table> | |||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>Two classes of errors can occur when <var>Post</var> is invoked: | <li>Two classes of errors can occur when <var>Post</var> is invoked: | ||
<ul> | <ul> | ||
<li>The HTTP request completed, but the server indicated a failure of the request | <li>The HTTP request completed, but the server indicated a failure of the request (an HTTP return code of 400 or greater). An example of this is the "404 not found" message issued by a web server when a non-existent document is referenced. In this class of error there was no TCP/IP communication error. | ||
(an HTTP return code of 400 or greater). | |||
An example of this is the "404 not found" message issued by a web server when a | |||
non-existent document is referenced. | |||
In this class of error there was no TCP/IP communication error. | |||
For these errors, the request is never cancelled, and an <var>[[ | For these errors, the request is never cancelled, and an <var>[[HttpResponse class|HttpResponse]]</var> object is always returned. The application handles these errors by [[HTTP Helper#The HttpResponse class|checking]] the <var>HTTPResponse</var> <var>[[Code_(HttpResponse_function)|Code]]</var>, <var>[[StatusLine_(HttpResponse_function)|StatusLine]]</var>, <var>[[Message_(HttpResponse_function)|Message]]</var>, and <var>[[Success_(HttpResponse_function)|Success]]</var> methods. | ||
is always returned. | <li>While attempting the HTTP request, a socket or communication error occurred. Examples of such errors include failure to connect to the server host, and a communication failure on a TCP/IP send or receive. | ||
The application handles these errors by [[The | |||
<var>HTTPResponse</var> | |||
<var>Code</var>, <var>StatusLine</var>, <var>Message</var>, and <var>Success</var> methods. | |||
<li>While attempting the HTTP request, a socket or communication error occurred. | |||
Examples of such errors include failure to connect to the server host, and a | |||
communication failure on a TCP/IP send or receive. | |||
For this class of errors, no instance of <var>HTTPResponse</var> is created, and | For this class of errors, no instance of <var>HTTPResponse</var> is created, and a <var>Null</var> object is returned. In addition, <var>[[$Status]]</var> is set to 1, and <var>[[$StatusD]]</var> is set to one of these: | ||
In addition, $ | |||
<ul> | <ul> | ||
<li>A negative return code that indicates an error in connecting to the | <li>A negative return code that indicates an error in connecting to the target HTTP server. These codes are the same as those in [[Get (HttpRequest function)#Get method return values|Get method return values]]. </li> | ||
target HTTP server. | |||
These codes are the same as those in [[Get method return values| | <li>A positive return code indicating a communications error after the connection was made. </li> | ||
<li>A positive return code indicating a communications error after | |||
the connection was made. | |||
</ul> | </ul> | ||
The request may or may not be cancelled based on the setting of | The request may or may not be cancelled based on the setting of the <var>Cancel</var> parameter. | ||
the | <p> | ||
Some of these errors are relatively benign (for example, inability to connect because remote partner down, timeout value exceeded), so they produce information-only messages, and they are treated as non-counting. These errors can still be detected and handled by the application (by checking for a <var>Null</var> result object, checking <var>$Status</var> and <var>$StatusD</var>, or both). </p> | |||
<blockquote class="note"> | |||
<p>'''Note:''' The distinctions between some of the return codes might or might not be meaningful, depending on the situation. For example, network problems can cause a 101 return code (indicating a timeout) or a 102 (indicating a connection closed). Connecting to a server that is using a non-HTTP protocol can result in a 100 (invalid format data received from the server) or a 101 or 102, depending on the protocol used by the server to which the request is sent: a request sent to a telnet port '''usually''' results in a timeout (return code 101), while a request sent to an SSL port without using <code>https</code> to indicate SSL '''usually''' results in the target server breaking the connection (return code 102).</p> | |||
<p> | |||
In general, it is risky to take action based on the distinction between the various non-zero error codes returned by this method.</p></blockquote> | |||
</ul> | |||
''' | |||
For more information about an error, you may want to issue a <var>[[JANUS TRACE]]</var> command with a value of 8 or 15 for the <var>[[JANUS CLSOCK|CLSOCK]]</var> port that is handling your HTTP request. | |||
<li>If form fields are defined with <var>[[AddField (HttpRequest subroutine)|AddField]]</var>, no explicit content type is set with <var>[[AddHeader (HttpRequest subroutine)|AddHeader]]</var>, and multipart form encoding is ''not'' enabled with <var>[[MultiPartFormEncoding (HttpRequest property)|MultiPartFormEncoding]]</var>, the <var class="product">HTTP Helper</var> automatically sends the following request header on <var>Post</var> calls: | |||
<p class="code">content-type: application/x-www-form-urlencoded | |||
</p> | |||
<li>For HTTP Version 1.1 mode only, the HTTP request header "connection: close" is automatically sent on HTTP requests to ensure that the server closes the connection with the client when the HTTP request completes. The HTTP Helper does '''not''' support persistent connections. </li> | |||
<li>The HTTP request header "Content-Length" is automatically sent on POSTs, accompanied by the value of the number of bytes in the non-header posted data. </li> | |||
<li>If the ports associated with the sockets in the HTTP request are not using SSL, and the <var>CertificateCheck</var> argument is specified, the <var class="term">certificateChecker</var> function does not get called. </li> | |||
</ul> | </ul> | ||
==See also== | |||
<ul> | |||
< | |||
<li>You can also send an HTTP POST using the <var>[[Send (HttpRequest function)|Send]]</var> method. | <li>You can also send an HTTP POST using the <var>[[Send (HttpRequest function)|Send]]</var> method. | ||
</ul> | </ul> | ||
{{Template:HttpRequest:Post footer}} | {{Template:HttpRequest:Post footer}} |
Latest revision as of 20:29, 8 December 2015
Send an HTTP POST request to the server (HttpRequest class)
The Post method sends an HTTP request to an HTTP server in the HTTP Post format: the request syntax sent to the server is the same as if a METHOD="POST"
HTML form was submitted from a web browser.
For more information about the HTTP POST request format, and for information about the HTTP protocol, refer to http://www.w3.org/Protocols/rfc2616/rfc2616.html.
Syntax
%httpResponse = httpRequest:Post[( [[Port=] string], [[Cancel=] number], - [CertificateCheck= certificateChecker], - [CheckKeepAliveCertificate= boolean])]
Syntax terms
%httpResponse | A reference to the HTTPResponse object instantiated and returned by this Post method. |
---|---|
httpRequest | An instantiated HttpRequest object that contains the request (its methods were used to create the request). |
Port | A string expression that identifies a previously defined CLSOCK port. The string default is the MASTER port, if any is defined. However, if you omit string and no MASTER port is defined, the request is canceled.
This is an optional and name-allowed parameter. If you specify a value, you may (but don't have to) specify the parameter name, Port (case not important). |
Cancel | A numeric expression that controls whether the request is cancelled if a communication/socket error occurs. If zero, the request is not cancelled on these errors. If non-zero, the request is cancelled (though a message is still issued). If not specified, it defaults to 1 (cancel). See "Usage notes," below, for further discussion of error handling.
This is an optional and name-allowed parameter. If you specify a value, you may (but don't have to) specify the parameter name, Cancel (case not important) if you want. |
CertificateCheck | This optional (name required) argument invokes an SSL certificate request from the server at the time of the method call.
The argument value (certificateChecker) must be a function, presumably local, with this method template: Function (String):methname Is Boolean When a connection is established, the passed function is called with the certificate (binary, ASN.1 encoded, content copied to a Longstring) as its method object.
For a CertificateCheck function example, see Examples for the Get method. |
CheckKeepAliveCertificate | This optional, name required, argument controls how frequently a specified CertificateCheck function is invoked for a an HTTP keep-alive connection. If False , the default, the certificateChecker function is called only when the physical connection is first established and not for every HTTP request on that connection. If set to True , the CertificateCheck method is called for every request, keep-alive or not.
|
Usage notes
- Two classes of errors can occur when Post is invoked:
- The HTTP request completed, but the server indicated a failure of the request (an HTTP return code of 400 or greater). An example of this is the "404 not found" message issued by a web server when a non-existent document is referenced. In this class of error there was no TCP/IP communication error. For these errors, the request is never cancelled, and an HttpResponse object is always returned. The application handles these errors by checking the HTTPResponse Code, StatusLine, Message, and Success methods.
- While attempting the HTTP request, a socket or communication error occurred. Examples of such errors include failure to connect to the server host, and a communication failure on a TCP/IP send or receive.
For this class of errors, no instance of HTTPResponse is created, and a Null object is returned. In addition, $Status is set to 1, and $StatusD is set to one of these:
- A negative return code that indicates an error in connecting to the target HTTP server. These codes are the same as those in Get method return values.
- A positive return code indicating a communications error after the connection was made.
The request may or may not be cancelled based on the setting of the Cancel parameter.
Some of these errors are relatively benign (for example, inability to connect because remote partner down, timeout value exceeded), so they produce information-only messages, and they are treated as non-counting. These errors can still be detected and handled by the application (by checking for a Null result object, checking $Status and $StatusD, or both).
Note: The distinctions between some of the return codes might or might not be meaningful, depending on the situation. For example, network problems can cause a 101 return code (indicating a timeout) or a 102 (indicating a connection closed). Connecting to a server that is using a non-HTTP protocol can result in a 100 (invalid format data received from the server) or a 101 or 102, depending on the protocol used by the server to which the request is sent: a request sent to a telnet port usually results in a timeout (return code 101), while a request sent to an SSL port without using
https
to indicate SSL usually results in the target server breaking the connection (return code 102).In general, it is risky to take action based on the distinction between the various non-zero error codes returned by this method.
For more information about an error, you may want to issue a JANUS TRACE command with a value of 8 or 15 for the CLSOCK port that is handling your HTTP request.
- If form fields are defined with AddField, no explicit content type is set with AddHeader, and multipart form encoding is not enabled with MultiPartFormEncoding, the HTTP Helper automatically sends the following request header on Post calls:
content-type: application/x-www-form-urlencoded
- For HTTP Version 1.1 mode only, the HTTP request header "connection: close" is automatically sent on HTTP requests to ensure that the server closes the connection with the client when the HTTP request completes. The HTTP Helper does not support persistent connections.
- The HTTP request header "Content-Length" is automatically sent on POSTs, accompanied by the value of the number of bytes in the non-header posted data.
- If the ports associated with the sockets in the HTTP request are not using SSL, and the CertificateCheck argument is specified, the certificateChecker function does not get called.
See also
- You can also send an HTTP POST using the Send method.