AddField (HttpRequest subroutine): Difference between revisions
m (1 revision) |
m (1 revision) |
||
Line 8: | Line 8: | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%httpreq</th> | <tr><th>%httpreq</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 15: | Line 15: | ||
</td></tr> | </td></tr> | ||
<tr><th>fieldvalue</th> | <tr><th>fieldvalue</th> | ||
<td>A <var>Longstring</var> or a <var>Stringlist</var> object expression that results in a value for the field. If it is a <var>Stringlist</var>, a line-end sequence is appended to each <var>Stringlist</var> item as it is added to the Post data. The <var>[[LineEnd ( | <td>A <var>Longstring</var> or a <var>Stringlist</var> object expression that results in a value for the field. If it is a <var>Stringlist</var>, a line-end sequence is appended to each <var>Stringlist</var> item as it is added to the Post data. The <var>[[LineEnd (HttpRequest property)|LineEnd]]</var> property sets which of three line-end sequence options is appended. | ||
</td></tr> | </td></tr> | ||
<tr><th>file</th> | <tr><th>file</th> | ||
Line 26: | Line 26: | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>See <var>[[MultipartFormEncoding ( | <li>See <var>[[MultipartFormEncoding (HttpRequest property)]]</var> for information about using <var>AddField</var> | ||
for a form used to Post file data. | for a form used to Post file data. | ||
<li><var>AddField</var> is designed for requests that have the | <li><var>AddField</var> is designed for requests that have the | ||
Line 34: | Line 34: | ||
content type. | content type. | ||
<li>If form fields are defined with <var>AddField</var>, no explicit content type is set | <li>If form fields are defined with <var>AddField</var>, no explicit content type is set | ||
with <var>[[AddHeader ( | with <var>[[AddHeader (HttpRequest subroutine)|AddHeader]]</var>, | ||
and multipart form encoding is ''not'' enabled with | and multipart form encoding is ''not'' enabled with | ||
<var>[[MultiPartFormEncoding ( | <var>[[MultiPartFormEncoding (HttpRequest property)|MultiPartFormEncoding]]</var>. | ||
the <var class="product">HTTP Helper</var> automatically sends the following request | the <var class="product">HTTP Helper</var> automatically sends the following request | ||
header on Post calls: | header on Post calls: | ||
Line 46: | Line 46: | ||
==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 | 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 | ||
%request is object | %request is object HttpRequest | ||
%response is object HTTPResponse | %response is object HTTPResponse | ||
%upfile is object <var>Stringlist</var> | %upfile is object <var>Stringlist</var> |
Revision as of 20:17, 16 June 2011
Add a form field to the request (HttpRequest class)
This 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
%httpreq | 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. |
xlatflag | This optional parameter controls whether the fieldvalue content gets EBCDIC-to-ASCII translation. If xlatflag is not specified, the default is True (use EBCDIC-to-ASCII translation). If the value is False, no translation occurs. |
Usage notes
- See MultipartFormEncoding (HttpRequest property) 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, a "text/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.
the HTTP Helper automatically sends the following request
header on Post calls:
content-type: application/x-www-form-urlencoded
- For information about Stringlist processing, see "Stringlist class".
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