Post (HttpRequest function): Difference between revisions
m (1 revision) |
m (match syntax table to syntax template; edits, tags and links) |
||
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 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== | ==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 [[HttpResponse_class|HTTPResponse]] 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 | <tr><th><var>Port</var></th> | ||
<td>A string expression that identifies a previously defined | <td>A string expression that identifies a previously defined <var>CLSOCK</var> port. The ''name'' default is the [[MASTER]] port, if any is defined. However, if you omit ''name'' and no <var>MASTER</var> port is defined, the request is canceled. | ||
This | This is an optional and (as of <var class="product">[[Sirius Mods]]</var> version 7.2) [[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) if you wish. | ||
</td></tr> | </td></tr> | ||
<tr><th><var>Cancel | <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 below for further discussion of error handling. | <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 | This is an optional and (as of <var class="product">Sirius Mods</var> version 7.2) 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 wish. | ||
</td></tr></table> | </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>[[HTTPResponse class|HTTPResponse]]</var> object | 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 [[The HTTPResponse methods#Status reporting|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 HTTPResponse methods#Status reporting|checking]] 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, $STATUS is set to 1, and $STATUSD is set to one of these: | ||
In addition, $STATUS is set to 1, and $STATUSD is set to one of these: | |||
<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"]]. | ||
target HTTP server. | <li>A positive return code indicating a communications error after the connection was made. | ||
These codes are the same as those in [[ | |||
<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 class="term">cancel</var> parameter. | ||
the | |||
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 $STATUS and $STATUSD, or both). | |||
'''Note:''' The distinctions between some of the return codes might or might not be meaningful, depending on the situation. | |||
'''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 | 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). | ||
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). | |||
In general, it is risky to take action based on the | In general, it is risky to take action based on the distinction between the various non-zero error codes returned by this method. | ||
distinction between the various non-zero error codes returned by this method. | |||
</ul> | </ul> | ||
For more information about an error, you may want to | For more information about an error, you may want to issue a <var>[[JANUS TRACE command|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. | ||
issue a <var>[[JANUS TRACE command|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 [[AddHeader (HttpRequest subroutine)|AddHeader]], and multipart form encoding is ''not'' enabled with <var>[[MultiPartFormEncoding (HttpRequest property)|MultiPartFormEncoding]]</var>, the HTTP Helper automatically sends the following request header on <var>Post</var> calls: | |||
<li>If form fields are defined with <var>[[AddField (HttpRequest subroutine)|AddField]]</var>, | |||
no explicit content type is set | |||
with [[AddHeader (HttpRequest subroutine)|AddHeader]], | |||
and multipart form encoding is ''not'' enabled with | |||
<var>[[MultiPartFormEncoding (HttpRequest property)|MultiPartFormEncoding]]</var>, | |||
the HTTP Helper automatically sends the following request | |||
header on Post calls: | |||
<p class="code"> content-type: application/x-www-form-urlencoded | <p class="code"> content-type: application/x-www-form-urlencoded | ||
</p> | </p> | ||
<li>For HTTP Version 1.1 mode only, | <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. | ||
the HTTP request header & | <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. | ||
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>The HTTP request header & | |||
sent on POSTs, accompanied by the value of the number of bytes in the | |||
non-header posted data. | |||
<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> | ||
==See also== | ==See also== | ||
<ul> | |||
<li>For more information about $STATUS and $STATUSD, see the <var class="product">Model 204</var> <i><b>User Language Manual</b></i> | |||
</ul> | |||
{{Template:HttpRequest:Post footer}} | {{Template:HttpRequest:Post footer}} |
Revision as of 01:30, 19 June 2011
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 name default is the MASTER port, if any is defined. However, if you omit name and no MASTER port is defined, the request is canceled.
This is an optional and (as of Sirius Mods version 7.2) name-allowed parameter. If you specify a value, you may (but don't have to) specify the parameter name, Port (case not important) if you wish. |
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 (as of Sirius Mods version 7.2) 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 wish. |
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.
- You can also send an HTTP POST using the Send method.
See also
- For more information about $STATUS and $STATUSD, see the Model 204 User Language Manual