0
我使用cURL,但直到現在我用它從服務器請求數據。但是現在我想要寫入API並且將用cURL請求數據。但我不知道Server如何從cURL請求中讀取數據。cURL請求的服務器端腳本
這是我的「客戶端服務器」端請求:
function sendRequest($site_name,$send_xml,$header_type=array('Content-Type: text/xml'))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$site_name);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$send_xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header_type);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$result = curl_exec($ch);
return $result;
}
$xml = "<request>
<session>
<user>exampleuser</user>
<pass>examplepass</pass>
</session>
</request>";
$sendreq = sendRequest("http://sitename.com/example.php",$xml);
echo $sendreq;
如何做我需要寫「主服務器」端腳本,所以我可以讀到用戶和請求通過的??? 非常感謝。
PHP在服務器上執行......這是沒有意義的。 –
@DigitalChris當我說客戶端是「客戶端服務器」,運行應用程序,服務器是「主服務器」 – mandza
如果您必須使用XML,那麼您需要在example.php中使用XML解析器。如果您更靈活地使用HTTP發佈請求來避免XML解析器的開銷。 –