我已經建立了一個使用php的自定義API,它是一個簡單的API,通過發佈XML數據。 ,我的工作張貼到API的代碼是:發送回覆 - PHP API
<?php
$xml_data = '<document>
<first>'.$first.'</first>
<last>'.$last.'</last>
<email>'.$email.'</email>
<phone>'.$phone.'</phone>
<body>TEST</body>
</document>';
$URL = "url";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$Response = curl_exec($ch);
curl_close($ch);
echo "Responce= ".$responce;
?>
在另一邊,上面代碼中的職位,以:
<?php
$postdata = file_get_contents("php://input");
$xml = simplexml_load_string($postdata);
$first = $xml->first;
$last = $xml->last;
$email = $xml->email;
$phone = $xml->phone;
?>
然後我把這些PHP變量和發送到數據庫..所有這個代碼工作!
但我的問題是:如何將回復發送回發帖方? 如何使用curl_init發送到curl_exec?
任何幫助將是偉大的!謝謝 傑森
你爲什麼要叫'curl_exec'兩次退回? – Madbreaks
錯誤,對不起!進出口和關閉,離開反應和關閉。另一個錯誤是 – user1789437