Page 1 of 1

requesting with http

Posted: Sun Dec 17, 2006 12:48 pm
by wackyakmed
I've got a script that is called by a client, and needs to request an http response from another site by passing it xml information in its body. I've done a similar thing in php before, but never involving passing body information to the the other site, only the filename with the info being passed in GET format.

ex:

Code: Select all

// Get a website response into an array. 
$lines = file('http://www.xxx.com/' . $_GET['name']);
Is there a command that would allow me to accomplish the same thing, while passing XML data as well, ie:

-request the page http://www.xxx.com
-send along this text with the request: <?xml version="1.0" encoding="UTF-8"?><response>...</response>';

The xml data can't be stored in GET or POST, it has to be passed in the request body

Thanks very much.

Posted: Sun Dec 17, 2006 12:54 pm
by volka
Depending on your php version you might use stream_context_create
Take a look at example M-2 at http://www.php.net/manual/en/wrappers.http.php
Instead of
$postdata = http_build_query
you would pass your xml string.

Posted: Sun Dec 17, 2006 12:54 pm
by feyd
I'll guess you will need to use fsockopen() et al to accomplish this.

Posted: Sun Dec 17, 2006 3:17 pm
by wackyakmed
Using stream_context_create worked like a charm. Thanks, guys!