requesting with http

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wackyakmed
Forum Newbie
Posts: 12
Joined: Sat Dec 16, 2006 10:37 am

requesting with http

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
Last edited by volka on Sun Dec 17, 2006 12:55 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'll guess you will need to use fsockopen() et al to accomplish this.
wackyakmed
Forum Newbie
Posts: 12
Joined: Sat Dec 16, 2006 10:37 am

Post by wackyakmed »

Using stream_context_create worked like a charm. Thanks, guys!
Post Reply