0

I have a php file that tries to send xml data to a web servie through curl but it never goes passing the curl_exec() function.

Client Code

$url = 'http://localhost:63342/eShop/RestWs/cdService.php/';

$data = '<cds><cd><title>' . $_POST['title'] . '</title><artist>' . $_POST['artist'] .
    '</artist><year>' . $_POST['year'] . '</year></cd></cds>';



$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));

$start = array_sum(explode(' ', microtime()));
$result = curl_exec($ch);
$stop = array_sum(explode(' ', microtime()));
$totalTime = $stop - $start;

if(curl_errno($ch)){
    echo 'Curl error: ' . curl_error($ch);
}

echo $result;

curl_close($ch);

Server Code

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

echo 'hi';

$input = file_get_contents('php://input');

$xml = simplexml_load_string($input);
echo($xml);

}

any ideas?

  • are you seeing the request in your access_log? safe to assume that your web server is listening on that port? can you hit the web service from your browser and get a response? i don't see anything obviously wrong with the structure of your curl request, itself... – J. Paulding Jul 09 '14 at 17:28
  • i am kind of a newbie, how can i hit my web service from the browser? whith an xml? like cdService.php?tasdas ? – user3821452 Jul 09 '14 at 17:36
  • What's the output when you debug the curl request? http://stackoverflow.com/a/14436877/367456 - What happens when you set timeout limits to little values, like timeout in one second? – hakre Jul 09 '14 at 18:10
  • maybe i'm misunderstanding what you misunderstand. just put the url "http://localhost:63342/eShop/RestWs/cdService.php" into your browser. don't even bother sending post data. see what happens. and then look at your web server access_log to see if it's getting that far. should help to narrow down where your problems could be. – J. Paulding Jul 10 '14 at 13:26

0 Answers0