ContentToStringlist (HttpResponse function): Difference between revisions
m (1 revision) |
mNo edit summary |
||
Line 3: | Line 3: | ||
This method | This method | ||
places into a Stringlist object the content returned | places into a Stringlist object the content returned | ||
from an | from an <var>[[HttpRequest class|HttpRequest]]</var> <var>[[Get (HttpRequest function)|Get]]</var>, <var>[[Post (HttpRequest function)|Post]]</var>, or <var>[[Send (HttpRequest function)|Send]]</var> method. | ||
ContentToStringlist does the following: | <var>ContentToStringlist</var> does the following: | ||
<ol> | <ol> | ||
<li>Instantiates a Stringlist object. | <li>Instantiates a <var>Stringlist</var> object. | ||
<li>Breaks the | <li>Breaks the <var>HttpRequest</var> returned content into lines by scanning for line-ends. | ||
<li>Translates each line from ASCII to EBCDIC, and places it in its own | <li>Translates each line from ASCII to EBCDIC, and places it in its own | ||
Stringlist element in the Stringlist it created. | <var>Stringlist</var> element in the <var>Stringlist</var> it created. | ||
<li>Returns the Stringlist. | <li>Returns the <var>Stringlist</var>. | ||
</ol> | </ol> | ||
==Syntax== | ==Syntax== | ||
Line 39: | Line 39: | ||
getting readable output for debugging purposes. | getting readable output for debugging purposes. | ||
For example, you can string together the <var>ContentToStringlist</var> and | For example, you can string together the <var>ContentToStringlist</var> and | ||
<var>[[Print ( | <var>[[Print (HttpResponse subroutine)|Print]]</var> methods: | ||
<p class="code"> %myGradeBookResponse:contentToStringlist:print | <p class="code"> %myGradeBookResponse:contentToStringlist:print | ||
</p> | </p> | ||
Line 80: | Line 80: | ||
</p> | </p> | ||
==See also== | ==See also== | ||
<ul> | <ul> | ||
<li>For information about returning response contents into a <var>Longstring</var>, | <li>For information about returning response contents into a <var>Longstring</var>, | ||
see <var>[[Content (HttpResponse function)|Content]]</var>. | see <var>[[Content (HttpResponse function)|Content]]</var>. | ||
</ul> | </ul> | ||
{{Template:HttpResponse:ContentToStringlist footer}} |
Revision as of 21:37, 17 June 2011
HTTP response data split into lines (HttpResponse class)
This method
places into a Stringlist object the content returned
from an HttpRequest Get, Post, or Send method.
ContentToStringlist does the following:
- Instantiates a Stringlist object.
- Breaks the HttpRequest returned content into lines by scanning for line-ends.
- Translates each line from ASCII to EBCDIC, and places it in its own Stringlist element in the Stringlist it created.
- Returns the Stringlist.
Syntax
%sl = httpResponse:ContentToStringlist
Syntax terms
%lines | A Stringlist object. |
---|---|
%httpresp | A reference to an HTTPResponse object that was returned by a Get, Post, or Send method of an HTTPRequest object. |
Usage notes
- No single HTTPResponse content line may exceed 6124 bytes in length (excluding the line end), or the request is cancelled. The scanned-for line-ends are the three typical characters (CRLF, CR, LF).
- This method is useful when the content returned from the HTTP server is a series of ASCII text lines separated by line-end characters (for example, an HTML document). Accessing such content with the HTTPResponse Content method would leave all the lines in one Longstring, which the application would have to separate into lines using string-handling User Language code.
- ContentToStringlist is also useful for
getting readable output for debugging purposes.
For example, you can string together the ContentToStringlist and
Print methods:
%myGradeBookResponse:contentToStringlist:print
The statement above produces much more readable output than this:
print %myGradeBookResponse:content
Example
The following code prompts for a URL, fetches the page at that URL, places it in a Stringlist using ContentToStringlist, and displays the lines.
begin %HTTPRequest is object HTTPRequest %HTTPResponse is object HTTPResponse %myPage is object Stringlist %i is float %HTTPRequest = new %HTTPRequest:URL = $read('Hey Moe, give me a URL!') %HTTPResponse = %HTTPRequest:Get('XMLCLIENT', 0 ) if ( %httpResponse is null ) then print 'Could not connect' stop end if if ( %HTTPResponse:Code = 200 ) then %myPage = %HTTPResponse:ContentToStringlist print %myPage:Count and 'lines obtained.' for %i from 1 to %myPage:count print 'Line' and %i and ': ' and %myPage:item(%i) at 15 end for else print 'Sorry dude, you got an error: ' and - %HTTPResponse:statusline end if end
See also
- For information about returning response contents into a Longstring, see Content.