php restful web service curl hangs

时间:2014-07-09 17:06:57

标签: php xml web-services curl

我有一个php文件试图通过curl将xml数据发送到web服务器,但它永远不会传递curl_exec()函数。

客户代码

$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);

服务器代码

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

echo 'hi';

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

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

}

任何想法?

0 个答案:

没有答案
相关问题