最近做的项目主要是针对socket以及接收post过来的xml信息并给出响应。
关于接收post过来xml的信息以及response
$file_in = file_get_contents(‘php://input’);
$request = simplexml_load_string($file_in);
$str = “……”;
echo $str;
关于接收response的信息:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
$response = curl_exec($ch);
if(curl_errno($ch))
{
print curl_error($ch);
}
var_dump($response);
以上就是一个完整的post发送和接收流程。
关于socket就不多说了。。
版权声明:本文为kxguan原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。