note 51360 added to ref.curl

From: Date: Mon, 28 Mar 2005 21:25:01 +0000
Subject: note 51360 added to ref.curl
Groups: php.notes 
Request: Send a blank email to php-notes+get-87107@lists.php.net to get a copy of this message
Had one heck of a time getting curl to send my XML request. Tried a lot of different things, FINALLY ended up with this. Im making a curl request to paymentech / Orbital 's payment gateway. Essentially, I took the same header i made for the fsockopen() request, and used it for this curl request. (Hostinc company didnt allow fsockopen(). You'll note that this specific gateway requires a custom content type header. Thats what gave me the most trouble. When using the CURLOPT_HTTPHEADER, and CURLOPT_POSTFIELDS together, it doesnt matter, it sends the default post header because of CURLOPT_POSTFIELDS. <?php $url = "https://your.gateway.url"; $page = "/proccessing_page.cgi"; $post_string = "<YourXML>All XML stuff Here</YourXML>"; $header = "POST ".$page." HTTP/1.0 \r\n"; $header .= "MIME-Version: 1.0 \r\n"; $header .= "Content-type: application/PTI26 \r\n"; $header .= "Content-length: ".strlen($post_string)." \r\n"; $header .= "Content-transfer-encoding: text \r\n"; $header .= "Request-number: 1 \r\n"; $header .= "Document-type: Request \r\n"; $header .= "Interface-Version: Test 1.4 \r\n"; $header .= "Connection: close \r\n\r\n"; $header .= $post_string; $ch = 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, $header); $data = curl_exec($ch); if (curl_errno($ch)) { print curl_error($ch); } else { curl_close($ch); } // use XML Parser on $data, and your set! $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0); xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE,1); xml_parse_into_struct($xml_parser, $data, $vals, $index); xml_parser_free($xml_parser); // $vals = array of XML tags. Go get em! ?> Worked like a dream for me. Enjoy! ---- Manual Page -- http://www.php.net/manual/en/ref.curl.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51360 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51360&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51360&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51360&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51360&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51360&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51360&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87107) next »