AddField (HttpRequest subroutine): Difference between revisions
m ((start) matching syntax terms to syntax box (will need further review when syntax box fixed), edits, tags and links.) |
m (→Syntax terms) |
||
(One intermediate revision by one other user not shown) | |||
Line 7: | Line 7: | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>httpRequest</th> | <tr><th>httpRequest</th> | ||
<td>A previously defined and instantiated <var> | <td>A previously defined and instantiated <var>HttpRequest</var> object. | ||
</td></tr> | </td></tr> | ||
<tr><th>fieldName</th> | <tr><th>fieldName</th> | ||
Line 19: | Line 19: | ||
<td>A string that identifies the file to be uploaded. The default is no file specification, that is, a non-file data Post. This is an optional parameter. | <td>A string that identifies the file to be uploaded. The default is no file specification, that is, a non-file data Post. This is an optional parameter. | ||
</td></tr> | </td></tr> | ||
<tr><th> | <tr><th>translate</th> | ||
<td>This optional parameter controls whether the <var class="term">fieldValue</var> content is processed with EBCDIC-to-ASCII translation. If <var class="term"> | <td>This optional <var>Boolean</var> parameter controls whether the <var class="term">fieldValue</var> content is processed with EBCDIC-to-ASCII translation. If <var class="term">translate</var> is not specified, the default is <var>True</var> (use EBCDIC-to-ASCII translation). If the value is <var>False</var>, no translation occurs. | ||
</td></tr></table> | </td></tr></table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>See <var>[[MultiPartFormEncoding (HttpRequest property)|MultiPartFormEncoding]]</var> for information about using <var>AddField</var> for a form used to Post file data. | <li>See <var>[[MultiPartFormEncoding (HttpRequest property)|MultiPartFormEncoding]]</var> for information about using <var>AddField</var> for a form used to Post file data. | ||
<li><var>AddField</var> is designed for requests that have the <code>application/x-www-form-urlencoded</code> or <code>multipart/form-data</code> content types. It is an error to use <var>AddField</var> in a request that has, say, a | <li><var>AddField</var> is designed for requests that have the <code>application/x-www-form-urlencoded</code> or <code>multipart/form-data</code> content types. It is an error to use <var>AddField</var> in a request that has, say, a <code>text/xml</code> content type. | ||
<li>If form fields are defined with <var>AddField</var>, no explicit content type is set with <var>[[AddHeader (HttpRequest subroutine)|AddHeader]]</var>, and multipart form encoding is ''not'' enabled with | <li>If form fields are defined with <var>AddField</var>, no explicit content type is set with <var>[[AddHeader (HttpRequest subroutine)|AddHeader]]</var>, and multipart form encoding is ''not'' enabled with | ||
<var> | <var>MultiPartFormEncoding (HttpRequest property)|MultiPartFormEncoding</var>. The <var class="product">HTTP Helper</var> automatically sends the following request | ||
header on Post calls: | header on <var>Post</var> calls: | ||
<p class="code"> content-type: application/x-www-form-urlencoded | <p class="code"> content-type: application/x-www-form-urlencoded | ||
</p> | </p> | ||
Line 35: | Line 36: | ||
==Example== | ==Example== | ||
The following <var class="product">User Language</var> prompts for a procedure name, stores the procedure in a <var>Stringlist</var>, and uploads the procedure using multipart form encoding. | |||
<p class="code">begin | <p class="code">begin | ||
%request is object httpRequest | %request is object httpRequest | ||
Line 64: | Line 64: | ||
print %response:[[Content_(HttpResponse_function)|content]] | print %response:[[Content_(HttpResponse_function)|content]] | ||
end | end | ||
</p | </p> | ||
==See also== | ==See also== |
Latest revision as of 15:31, 5 March 2013
Add a form field to the request (HttpRequest class)
The AddField method lets you add a form field name and value pair to the HTTP request that is to be sent to the HTTP server.
Syntax
httpRequest:AddField( fieldName, fieldValue, [file], [translate])
Syntax terms
httpRequest | A previously defined and instantiated HttpRequest object. |
---|---|
fieldName | A string expression that names an HTTP form field. Field names are case insensitive.
Passing multiple occurrences is allowed; if a same-named field is already present, an additional instance is added. |
fieldValue | A Longstring or a Stringlist object expression that results in a value for the field. If it is a Stringlist, a line-end sequence is appended to each Stringlist item as it is added to the Post data. The LineEnd property sets which of three line-end sequence options is appended. |
file | A string that identifies the file to be uploaded. The default is no file specification, that is, a non-file data Post. This is an optional parameter. |
translate | This optional Boolean parameter controls whether the fieldValue content is processed with EBCDIC-to-ASCII translation. If translate is not specified, the default is True (use EBCDIC-to-ASCII translation). If the value is False, no translation occurs. |
Usage notes
- See MultiPartFormEncoding for information about using AddField for a form used to Post file data.
- AddField is designed for requests that have the
application/x-www-form-urlencoded
ormultipart/form-data
content types. It is an error to use AddField in a request that has, say, atext/xml
content type. - If form fields are defined with AddField, no explicit content type is set with AddHeader, and multipart form encoding is not enabled with
MultiPartFormEncoding (HttpRequest property)|MultiPartFormEncoding. The HTTP Helper automatically sends the following request
header on Post calls:
content-type: application/x-www-form-urlencoded
Example
The following User Language prompts for a procedure name, stores the procedure in a Stringlist, and uploads the procedure using multipart form encoding.
begin %request is object httpRequest %response is object httpResponse %upfile is object stringlist %procname is string len 255 %rc is fixed %procname = $read('Enter proc name please') %rc = $procopn( %procname ) if ( %rc ) then print 'could not open the proc, dude.' stop end if %upfile = new %upfile:appendOpenProcedure %rc = $proccls %upfile:print %request = new %request:URL = 'whatever' %request:multiPartFormEncoding = true %request:lineEnd = CR %request:addField('filename',%upfile,%procname) %response = %request:post( 'CSOCK' ) print %response:statusline print %response:content end
See also
- For information about Stringlist processing, see "Stringlist class".