Difference between revisions of "Content (HttpResponse function)"

From m204wiki
Jump to navigation Jump to search
m (move footer template to actual end; match syntax table to syntax template; edits, tags and links)
m
 
Line 13: Line 13:
 
</td></tr>
 
</td></tr>
 
<tr><th>number</th>
 
<tr><th>number</th>
<td>An, optional, numeric expression that, if nonzero, indicates binary data. Setting this option overrides the default behavior, which is to translate ASCII data to EBCDIC.</td></tr>
+
<td>An optional, numeric expression that, if nonzero, indicates binary data. Setting this option overrides the default behavior, which is to translate ASCII data to EBCDIC.</td></tr>
 
</table>
 
</table>
  
Line 19: Line 19:
 
<ul>
 
<ul>
 
<li>Invoke <var>Content</var> only if a successful HTTP transaction has occurred, that is, if the <var>[[Success (HttpResponse function)|Success]]</var> value is <var>True</var>.  If <var>Content</var> is called after an unsuccessful operation, the request is cancelled.
 
<li>Invoke <var>Content</var> only if a successful HTTP transaction has occurred, that is, if the <var>[[Success (HttpResponse function)|Success]]</var> value is <var>True</var>.  If <var>Content</var> is called after an unsuccessful operation, the request is cancelled.
<li>If the content type header indicates HTML, XML, or plain text, ASCII-to-EBCDIC translation is performed.  If the <var>Clsock</var> port definition specifies a translation table for ASCII-to-EBCDIC, that table is used instead of the default.
+
<li>If the content type header indicates HTML, XML, or plain text, ASCII-to-EBCDIC translation is performed.  If the <var>[[JANUS DEFINE#type|CLSOCK]]</var> port definition specifies a translation table for ASCII-to-EBCDIC, that table is used instead of the default.
 
</ul>
 
</ul>
  
 
==Example==
 
==Example==
<ol>
+
In the following fragment, an <var>HTTPResponse</var> object receives a .PDF file from a remote URL into a <var>Longstring</var>, leaving the data in binary format:
<li>In the following fragment, an <var>HTTPResponse</var> object receives a .PDF file from a remote URL into a <var>Longstring</var>, leaving the data in binary format:
 
 
<p class="code">  %httpreq  is object httpRequest
 
<p class="code">  %httpreq  is object httpRequest
 
   %httpresp  is object httpResponse
 
   %httpresp  is object httpResponse
Line 36: Line 35:
 
       %pdf = %httpresp:content(1)
 
       %pdf = %httpresp:content(1)
 
     ...
 
     ...
</p></ol>
+
</p>
  
 
==See also==
 
==See also==

Latest revision as of 19:55, 20 June 2011

Get raw HTTP response data (HttpResponse class)

The Content method lets you access the document/content from Get, Post, and Send operations. Content returns the entire document into a Longstring with no parsing: you receive the raw bytes as they were returned from the HTTP request, with the option of ASCII-to-EBCDIC translation.

Syntax

%string = httpResponse:Content[( [number])]

Syntax terms

%string A longstring variable to receive the current document/content.
httpResponse A reference to an HttpResponse object that was returned by a Get, Post, or Send method of an HttpRequest object.
number An optional, numeric expression that, if nonzero, indicates binary data. Setting this option overrides the default behavior, which is to translate ASCII data to EBCDIC.

Usage notes

  • Invoke Content only if a successful HTTP transaction has occurred, that is, if the Success value is True. If Content is called after an unsuccessful operation, the request is cancelled.
  • If the content type header indicates HTML, XML, or plain text, ASCII-to-EBCDIC translation is performed. If the CLSOCK port definition specifies a translation table for ASCII-to-EBCDIC, that table is used instead of the default.

Example

In the following fragment, an HTTPResponse object receives a .PDF file from a remote URL into a Longstring, leaving the data in binary format:

%httpreq is object httpRequest %httpresp is object httpResponse %pdf is longstring %url is longstring ... %httpreq = new %httpreq:url = %url %httpresp = %httpreq:get if (%httpresp:Success) then %pdf = %httpresp:content(1) ...

See also

  • For information about returning response contents into a Stringlist, see the ContentToStringlist method.