note 80271 added to ref.curl

From: Date: Mon, 07 Jan 2008 17:48:03 +0000
Subject: note 80271 added to ref.curl
Groups: php.notes 
Request: Send a blank email to php-notes+get-134925@lists.php.net to get a copy of this message
After much struggling, I managed to get a SOAP request requiring HTTP authentication to work. Here's some source that will hopefully be useful to others. <?php $credentials = "username:password"; // Read the XML to send to the Web Service $request_file = "./SampleRequest.xml"; $fh = fopen($request_file, 'r'); $xml_data = fread($fh, filesize($request_file)); fclose($fh); $url = "http://www.myservicehost.com/services/calculation"; $page = "/services/calculation"; $headers = array( "POST ".$page." HTTP/1.0", "Content-type: text/xml;charset=\"utf-8\"", "Accept: text/xml", "Cache-Control: no-cache", "Pragma: no-cache", "SOAPAction: \"run\"", "Content-length: ".strlen($xml_data), "Authorization: Basic " . base64_encode($credentials) ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']); // Apply the XML to our curl call curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data); $data = curl_exec($ch); if (curl_errno($ch)) { print "Error: " . curl_error($ch); } else { // Show me the result var_dump($data); curl_close($ch); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 74.139.251.101 ---- Manual Page -- http://www.php.net/manual/en/ref.curl.php Edit -- https://master.php.net/note/edit/80271 Del: integrated -- https://master.php.net/note/delete/80271/integrated Del: useless -- https://master.php.net/note/delete/80271/useless Del: bad code -- https://master.php.net/note/delete/80271/bad+code Del: spam -- https://master.php.net/note/delete/80271/spam Del: non-english -- https://master.php.net/note/delete/80271/non-english Del: in docs -- https://master.php.net/note/delete/80271/in+docs Del: other reasons-- https://master.php.net/note/delete/80271 Reject -- https://master.php.net/note/reject/80271 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134925) next »