plz help: using curl to post an xml string

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
woohoo
Forum Newbie
Posts: 1
Joined: Thu Jul 06, 2006 9:19 am

plz help: using curl to post an xml string

Post by woohoo »

This is the code in ASP:

it just sends some xml data to another page.

Code: Select all

<%

stop

dim strURL, strContent

dim xmlhttp

dim oXMLCriteria 

Dim xmlPlainString

xmlPlainString = "<search><city>75</city><age>21</age></search>"

'page to http post to

strURL="http://www.examplesite.com/results_xml.aspx" 

set xmlhttp=Server.CreateObject("Microsoft.XMLHTTP")

call xmlhttp.Open("POST", strURL, false)

on error resume next


call xmlhttp.Send(xmlPlainString)

if err.number <> 0 then

strContent = err.Description

else

strContent = xmlhttp.responseText

end if

dim oXML 

'load xml property results into xml and do whatever formatting is necessary.

set oXML = server.CreateObject("msxml.domdocument")

oXML.loadXML(strContent)

Response.Clear()

Response.ContentType = "text/xml"

oXML.save response

response.end 

%>
Can someone please help me find a php equivelent? I have CURL but not DOM XML extensions.

Any help would be very much appreciated.

Heres what I've tried so far:

Code: Select all

$url = 'http://www.examplesite.com/results_xml.aspx';
	
	$ch = curl_init();
	curl_setopt ($ch, CURLOPT_URL, $url);
	curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
	curl_setopt ($ch, CURLOPT_HEADER, 0);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt ($ch, CURLOPT_TIMEOUT, 9);
	curl_setopt ($ch, CURLOPT_POSTFIELDS, "".urlencode("<search><city>75</city><age>21</age></search>"));
	curl_setopt ($ch, CURLOPT_POST, 1);
	echo $result2 = curl_exec ($ch);
	curl_close($ch);
Post Reply