POST problem with php & cURL

nsteele84
nsteele84 used Ask the Experts™
on
HI
 I am trying to post to a URL and receive a reply from it. I am trying to use cURL but it is new to me and I am having some problems Here is what I have so far:

$url = "http://production.shippingapis.com/ShippingAPI.dll?API=RateV4&XML=".$post_string;

$header = "POST HTTP/1.0 \r\n";
$header .= "Content-type: text/xml \r\n";
$header .= "Content-transfer-encoding: text \r\n";

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER ,0);
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);

echo("Return Data: $data  <P>");

if(curl_errno($ch)){
      $error =  print curl_error($ch);
      echo ("Curl Error: $error");
}else{
      curl_close($ch);
}


$post_string is a block of xml. This returns an error code of 1.

Any help would be appreciated.

Thanks Nick Steele
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011
Commented:
     $oCUrl = curl_init();
      curl_setopt($oCUrl, CURLOPT_TIMEOUT, 10); // Timeout value
      curl_setopt($oCUrl, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
      curl_setopt($oCUrl, CURLOPT_POST, true);
      curl_setopt($oCUrl, CURLOPT_VERBOSE, 1);
      curl_setopt($oCUrl, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($oCUrl, CURLOPT_SSL_VERIFYHOST, false);
      curl_setopt($oCUrl, CURLOPT_POSTFIELDS, 'API=RateV4&XML=' . $post_string);
      curl_setopt($oCUrl, CURLOPT_URL, 'http://production.shippingapis.com/ShippingAPI.dll');
      $data = curl_exec($ch);

Author

Commented:
Great Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial