Content (HttpResponse function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
mNo edit summary
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Template:HttpResponse:Content subtitle}}
{{Template:HttpResponse:Content subtitle}}
The <var>Content</var> method lets you access the document/content from <var>[[Get (HttpRequest function)|Get]]</var>, <var>[[Post (HttpRequest function)|Post]]</var>, and <var>[[Send (HttpRequest function)|Send]]</var> operations.  <var>Content</var> returns the entire document into a <var>[[longstrings|Longstring]]</var> with no parsing: you receive the raw bytes as they were returned from the HTTP request, with the option of ASCII-to-EBCDIC translation.


This 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 get the raw bytes as they were returned from the HTTP request, with the
option of ASCII-to-EBCDIC translation.
==Syntax==
==Syntax==
{{Template:HttpResponse:Content syntax}}
{{Template:HttpResponse:Content syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%longstring</th>
<tr><th>%string</th>
<td>A longstring variable.
<td>A <var>longstring</var> variable to receive the current document/content.
</td></tr>
</td></tr>
<tr><th>%httpresp</th>
<tr><th>httpResponse</th>
<td>A reference to an HTTPResponse object that was returned by a Get, Post, or Send method of an HTTPRequest object.
<td>A reference to an <var>[[HttpResponse_class|HttpResponse]]</var> object that was returned by a <var>Get</var>, <var>Post</var>, or <var>Send</var> method of an <var>[[HttpRequest_class|HttpRequest]]</var> object.
</td></tr>
</td></tr>
<tr><th>binflag</th>
<tr><th>number</th>
<td>A numeric expression that, if nonzero, indicates binary data. Setting this option overrides the default behaviour, which is to translate ASCII data to EBCDIC.
<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>


</td></tr></table>
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>Invoke <var>Content</var> only
<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.
if a successful HTTP transaction has occurred, that is, if
<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.
the <var>[[Success (HttpResponse property)|Success]]</var> property 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.
</ul>
</ul>
==Example==
==Example==
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
  %httpresp  is object httpResponse
  %pdf      is longstring
  %url      is longstring
    ...
  %httpreq = [[New_(HttpRequest_constructor)|new]]
  %httpreq:[[URL_(HttpRequest_property)|url]] = %url
  %httpresp = %httpreq:[[Get_(HttpRequest_function)|get]]
  if (%httpresp:Success) then
      %pdf = %httpresp:content(1)
    ...
</p>


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
%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)
  ...
</p>
==See also==
==See also==
{{Template:HttpResponse:Content footer}}
<ul>
<ul>
<li>For information about returning response contents into a <var>Stringlist</var>,
<li>For information about returning response contents into a <var>Stringlist</var>, see the <var>[[ContentToStringlist (HttpResponse function)|ContentToStringlist]]</var> method.
see the <var>[[ContentToStringlist (HttpResponse function)|ContentToStringlist]]</var> method.
</ul>
</ul>
{{Template:HttpResponse:Content footer}}

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.