Send (HttpRequest function): Difference between revisions
m (1 revision) |
m (misc cleanup) |
||
(18 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{Template: | {{Template:HttpRequest:Send subtitle}} | ||
The <var>Send</var> function sends an HTTP request to an HTTP server using a parameter value to identify which of the HTTP method types (GET, POST, DELETE, and so on) you want the function to perform. Any HTTP method type is valid as long as its name is 16 characters or less. | |||
The | The HTTP method type is specified with the <var>Method</var> ([[Notation conventions for methods#Named parameters|name required]]) parameter. If the <var>Method</var> value is <code>GET</code> or <code>POST</code>, the <var>Send</var> method invocation becomes equivalent to the <var>[[Get (HttpRequest function)|Get]]</var> or <var>[[Post (HttpRequest function)|Post]]</var> method. | ||
( | |||
The | The <var>Send</var> method is the only way to carry out HTTP methods other than GET or POST. | ||
==Syntax== | ==Syntax== | ||
{{Template: | {{Template:HttpRequest:Send syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table | <table> | ||
<tr><th>% | <tr><th>%httpresponse</th> | ||
<td>A reference to the | <td>A reference to the <var>[[HttpResponse class|HttpResponse]]</var> object instantiated and returned by this <var>Send</var> method. | ||
</td></tr> | </td></tr> | ||
<tr><th> | |||
<td>An instantiated | <tr><th>httpRequest</th> | ||
<td>An instantiated <var>HttpRequest</var> object that contains the request (its methods were used to create the request). | |||
</td></tr> | </td></tr> | ||
</td></tr></table> | <tr><th><var>Port</var></th> | ||
<td>A string expression that identifies a previously defined <var>CLSOCK</var> port. The default value is the [[MASTER]] port, if any is defined. However, if you do not specify a value 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. | |||
<p> | |||
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. </p></td></tr> | |||
<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 content, ASN.1 encoded, 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> | |||
For a <var>CertificateCheck</var> function example, see [[Get_(HttpRequest_function)#Examples|Examples]] for the <var>Get</var> method.</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> | |||
<tr><th><var>Method</var></th> | |||
<td><var>Method</var> is both a required and [[Methods#Named parameters|name required]] parameter that specifies the quoted name of any HTTP method type (for example, <code>'GET'</code>, <code>'PUT'</code>, <code>'MOVE'</code>). | |||
The parameter name, <var>Method</var>, is not case sensitive, but it must be supplied. The type <var class="term">name</var> must be less than or equal to 16 characters, all uppercase. </td></tr> | |||
</table> | |||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>Although you may specify the <var>Method</var> parameter before the optional | <li>Although you may specify the <var class="term>Method</var> parameter before the optional parameters, you receive a compilation error if you do so without also specifying the optional parameter names with the optional parameters. </li> | ||
parameters, you receive a compilation error if you do so without | |||
also specifying the optional parameter names with the optional parameters. | <li>For information about error handling, see the <var>Get</var> function [[Get (HttpRequest function)#Usage notes|"Usage notes"]]. | ||
<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> | ||
<li>For information about error handling, see | <li>To send an HTTP GET or POST, you can also use the <var>Get</var> method or the <var>Post</var> method, respectively. </li> | ||
[[Get ( | |||
<li>To send an HTTP GET or POST, you can also use the <var> | |||
or the <var> | |||
</ul> | </ul> | ||
==Examples== | ==Examples== | ||
<var>Send</var> statements with argument variations are shown below: | <var>Send</var> statements with argument variations are shown below: | ||
<p class="code"> %resp = %req:send(method='DELETE') | <p class="code">%resp = %req:send(method='DELETE') | ||
%resp = %req:send('CLPORT', method='DELETE') | |||
%resp = %req:send(method='POST', port='CLPORT', cancel=1) | |||
</p> | </p> | ||
==See also== | ==See also== | ||
{{Template: | <ul> | ||
<li>For information about the HTTP protocol, refer to http://www.w3.org/Protocols/rfc2616/rfc2616.html. </li> | |||
</ul> | |||
{{Template:HttpRequest:Send footer}} |
Latest revision as of 16:35, 15 March 2016
Send an HTTP request to the server (HttpRequest class)
The Send function sends an HTTP request to an HTTP server using a parameter value to identify which of the HTTP method types (GET, POST, DELETE, and so on) you want the function to perform. Any HTTP method type is valid as long as its name is 16 characters or less.
The HTTP method type is specified with the Method (name required) parameter. If the Method value is GET
or POST
, the Send method invocation becomes equivalent to the Get or Post method.
The Send method is the only way to carry out HTTP methods other than GET or POST.
Syntax
%httpResponse = httpRequest:Send( [[Port=] string], [[Cancel=] number], - [CertificateCheck= certificateChecker], - [CheckKeepAliveCertificate= boolean], - Method= name)
Syntax terms
%httpresponse | A reference to the HttpResponse object instantiated and returned by this Send 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 default value is the MASTER port, if any is defined. However, if you do not specify a value 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 content, ASN.1 encoded, copied to a Longstring) as its method object.
|
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. |
Method | Method is both a required and name required parameter that specifies the quoted name of any HTTP method type (for example, 'GET' , 'PUT' , 'MOVE' ).
The parameter name, Method, is not case sensitive, but it must be supplied. The type name must be less than or equal to 16 characters, all uppercase. |
Usage notes
- Although you may specify the Method parameter before the optional parameters, you receive a compilation error if you do so without also specifying the optional parameter names with the optional parameters.
- For information about error handling, see the Get function "Usage notes".
- 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.
- To send an HTTP GET or POST, you can also use the Get method or the Post method, respectively.
Examples
Send statements with argument variations are shown below:
%resp = %req:send(method='DELETE') %resp = %req:send('CLPORT', method='DELETE') %resp = %req:send(method='POST', port='CLPORT', cancel=1)
See also
- For information about the HTTP protocol, refer to http://www.w3.org/Protocols/rfc2616/rfc2616.html.