时间:2021-07-01 10:21:17 帮助过:5人阅读
POSTHTTP/1.0
USER-Agent:
Content-Type: application/x-fox
Content-Length: nnnn
...
if( $_SERVER['REQUEST_METHOD'] === 'POST' ){
// 接收
$content = file_get_contents('php://input');
$xml = simplexml_load_string($content);
echo "来自XML接收方的响应\n";
print_r( get_object_vars($xml) );
exit;
}
// 发送行为
$xml = <<
world
xml;
$setting = array(
'http' => array(
'method' => 'POST',
'user_agent' => '',
'header' => "Content-type: application/x-www-form-urlencoded",
'content' => $xml
)
);
$context = stream_context_create($setting);
$url = 'http://localhost/'. $_SERVER['REQUEST_URI'];
$response = file_get_contents($url, null, $context);
echo $response;