From: "Robert P. J. Day" on

just getting started with the HTTP_Request2 class, and i want to
create a POST request that passes potentially lots of data as uploaded
content. from the class definition in Request2.php, i can see:

/**
* Sets the request body
*
* @param string Either a string with the body or filename containing body
* @param bool Whether first parameter is a filename
* @return HTTP_Request2
* @throws HTTP_Request2_Exception
*/
public function setBody($body, $isFilename = false)
.... snip ...


fair enough but, once i send off the POST request to the remote PHP
file, how do i access that "body" content? i'm sure this is just a
trivial POST issue. i can examine $_SERVER['CONTENT_LENGTH'] to see
the *length* of the body, but i don't know what variable to use to get
the content itself. help?

rday
--


========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
========================================================================
From: Bill Shupp on
On Mar 3, 2010, at 3:13 PM, Robert P. J. Day wrote:

>
> just getting started with the HTTP_Request2 class, and i want to
> create a POST request that passes potentially lots of data as uploaded
> content. from the class definition in Request2.php, i can see:
>
> /**
> * Sets the request body
> *
> * @param string Either a string with the body or filename containing body
> * @param bool Whether first parameter is a filename
> * @return HTTP_Request2
> * @throws HTTP_Request2_Exception
> */
> public function setBody($body, $isFilename = false)
> ... snip ...
>
>
> fair enough but, once i send off the POST request to the remote PHP
> file, how do i access that "body" content? i'm sure this is just a
> trivial POST issue. i can examine $_SERVER['CONTENT_LENGTH'] to see
> the *length* of the body, but i don't know what variable to use to get
> the content itself. help?
>
> rday

$http = new HTTP_Request2('http://example.com');
$response = $http->send();
$body = $response->getBody();

Regards,

Bill
From: Alexey Borzov on
Hi Robert,

On 04.03.2010 2:13, Robert P. J. Day wrote:
> just getting started with the HTTP_Request2 class, and i want to
> create a POST request that passes potentially lots of data as uploaded
> content. from the class definition in Request2.php, i can see:
>
> /**
> * Sets the request body
> *
> * @param string Either a string with the body or filename containing body
> * @param bool Whether first parameter is a filename
> * @return HTTP_Request2
> * @throws HTTP_Request2_Exception
> */
> public function setBody($body, $isFilename = false)
> ... snip ...
>
>
> fair enough but, once i send off the POST request to the remote PHP
> file, how do i access that "body" content? i'm sure this is just a
> trivial POST issue. i can examine $_SERVER['CONTENT_LENGTH'] to see
> the *length* of the body, but i don't know what variable to use to get
> the content itself. help?

Please clarify: are you going to send a custom POST body (as in XML-RPC or SOAP)
or emulate POST file upload?

In the former case you access the body via php://input stream, in the latter
case you need addUpload() rather than setBody() and just access the $_FILES
array as usual.
From: "Robert P. J. Day" on
On Thu, 4 Mar 2010, Alexey Borzov wrote:

> Hi Robert,
>
> On 04.03.2010 2:13, Robert P. J. Day wrote:
> > just getting started with the HTTP_Request2 class, and i want
> > to create a POST request that passes potentially lots of data as
> > uploaded content. from the class definition in Request2.php, i
> > can see:
> >
> > /**
> > * Sets the request body
> > *
> > * @param string Either a string with the body or filename> > containing body
> > * @param bool Whether first parameter is a filename
> > * @return HTTP_Request2
> > * @throws HTTP_Request2_Exception
> > */
> > public function setBody($body, $isFilename = false)
> > ... snip ...
> >
> >
> > fair enough but, once i send off the POST request to the remote
> > PHP file, how do i access that "body" content? i'm sure this is
> > just a trivial POST issue. i can examine
> > $_SERVER['CONTENT_LENGTH'] to see the *length* of the body, but i
> > don't know what variable to use to get the content itself. help?
>
> Please clarify: are you going to send a custom POST body (as in
> XML-RPC or SOAP) or emulate POST file upload?
>
> In the former case you access the body via php://input stream, in
> the latter case you need addUpload() rather than setBody() and just
> access the $_FILES array as usual.

i want to send an arbitrary amount of *content* via a POST request
to a PHP script, so i think it's the former that i want. until now,
i've been able to do a standard file upload since the content was
always in a file, but now the content can come from anywhere so i have
to rewrite my program to accept raw bytes and just pass that on.
could be up to several megabytes.

from the Request2.php script, i can read about addUpload():

/**
* Adds a file to form-based file upload
*
* Used to emulate file upload via a HTML form. The method also sets
* Content-Type of HTTP request to 'multipart/form-data'.
*
* If you just want to send the contents of a file as the body of HTTP
* request you should use setBody() method...

and since i have no actual *file* but just the contents, i went with
setBody() but (not being a HTTP POST expert), i wasn't sure how to
extract the contents at the other end. now i see it's using
php://input stream. thanks, i'll give that a try shortly.

rday
--

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
========================================================================
From: "Robert P. J. Day" on
On Thu, 4 Mar 2010, Alexey Borzov wrote:

> Hi Robert,
>
> On 04.03.2010 2:13, Robert P. J. Day wrote:
> > just getting started with the HTTP_Request2 class, and i want
> > to create a POST request that passes potentially lots of data as
> > uploaded content. from the class definition in Request2.php, i
> > can see:
> >
> > /**
> > * Sets the request body
> > *
> > * @param string Either a string with the body or filename> > containing body
> > * @param bool Whether first parameter is a filename
> > * @return HTTP_Request2
> > * @throws HTTP_Request2_Exception
> > */
> > public function setBody($body, $isFilename = false)
> > ... snip ...
> >
> >
> > fair enough but, once i send off the POST request to the remote
> > PHP file, how do i access that "body" content? i'm sure this is
> > just a trivial POST issue. i can examine
> > $_SERVER['CONTENT_LENGTH'] to see the *length* of the body, but i
> > don't know what variable to use to get the content itself. help?
>
> Please clarify: are you going to send a custom POST body (as in
> XML-RPC or SOAP) or emulate POST file upload?
>
> In the former case you access the body via php://input stream, in
> the latter case you need addUpload() rather than setBody() and just
> access the $_FILES array as usual.

given that i don't know a whole lot (read: nothing) about custom
POST bodies, here's what i'm after. i want to put together a POST
request with which i can upload one or more POST parameters, plus an
arbitrary amount of content. i can't use the file upload feature
since i may not have a filename to go with the data, i'm just going to
be handed that content.

i know i can use addPostParameter() to pass those POST parameters,
and i can extract them at the other end by referring to $_POST. that
part's easy. but i don't see how to extend that to *additionally*
passing that single large chunk of content.

i suspect i could just make that another POST parameter whose value
would be a massively long stream of bytes. is there anything untoward
about that? or is there a better (more approved) way of doing what
i'm after? can i combine adding POST parameters with setting the
body?

rday
--

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
========================================================================