Avatar of nsteele84
nsteele84
 asked on

POST problem with php & cURL

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
PHP

Avatar of undefined
Last Comment
nsteele84

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rik-Legger

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
nsteele84

ASKER
Great Thanks
Your help has saved me hundreds of hours of internet surfing.
fblack61