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解析器的开销。 –