HTTP Post with xml Document

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
nivas41
Forum Newbie
Posts: 1
Joined: Mon Nov 08, 2010 12:25 am

HTTP Post with xml Document

Post by nivas41 »

HI All

I am very much new to PHP programmng. I am having requirement that I can call web API Through HTTP POST with with XML file.

I tried with

Code: Select all

	$url=" https://site.one.com";
	$post_string='<requestEnvelope xmlns="http://services.xyz.com/infoset"> <header> <credentials>    <userNameAndPassword> <name>satya</name> <password>xcvfder</password> </userNameAndPassword> </credentials> </header> <requests> <request tag="0:Network.GetSites()"> <service>network</service> <operation>getSites</operation> <arguments> <network id="1651410" /> </arguments> </request> </requests> </requestEnvelope>';

	$header = 'POST HTTP/1.0 \r\n';
	$header .= 'Content-type text/xml \r\n';
	$header .= 'Content-length: ".strlen($post_string)." \r\n';
	$header .= "Content-transfer-encoding: text \r\n";
	$header .= "Connection: close \r\n\r\n";
	$header .= $post_string;

                 curl_init(); 
                 curl_setopt($ch, CURLOPT_URL, $url);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt($ch, CURLOPT_TIMEOUT, 4);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 0);
	
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $header);
	
	$data = curl_exec($ch);
	
	if(curl_errno($ch))
		print curl_error($ch);
	else
		curl_close($ch);
functions and getting errow like below
'Protocol https not supported or disabled in libcurl !!! '

is there any other methods to post xml ..

Please guide me .. Thanks in advance for your help

Satya
Last edited by Weirdan on Mon Nov 08, 2010 2:45 am, edited 1 time in total.
Reason: added syntax highlighting
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: HTTP Post with xml Document

Post by s.dot »

You could try just regular post headers without curl.
Open a filestream, post the headers to it, and read back the response.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply