PHP file_get_contents函数详解
```php
$url = 'http://192.168.31.63/';
$data = array(
'item' => 'test data',
);
$content = http_build_query($data);
$content_length = strlen($content);
$options = array(
'http' => array(
'method' => 'POST',
'header' =>
"Content-type: application/x-www-form-urlencoded\r\n" .
"Content-length: $content_length\r\n",
'content' => $content
)
);
echo file_get_contents($url, false, stream_context_create($options));
2.php
<?php
/**
* @Author: anchen
* @Date: 2017-03-23 13:51:46
* @Last Modified by: anchen
* @Last Modified time: 2017-03-23 13:53:46
*/
file_put_contents('./', var_export($_POST, true));//把接收的数据储存起来
下面写一个贴近一点的例子
$data = [
'author' => '白菜打下',
'mail' => 'info@',
'text' => '博主很给力',
];
$data = http_build_query($data);
$opts = [
'http' => [
'method' => 'POST',
'header' => "Content-type:application/x-www-form-urlencoded\r\n".
"Content-Length: ".strlen($data)."\r\n".
"Cookie: PHPSESSID=13ROTEGFGJDFDFDOGDFGD"."\r\n".
"User-Agent: Mozilla/5.0(Windows: U; Windows NT 6.1; zh-CH; rv: 1.9.2.13) Gecko/20101203 Firefox/3.6.13"."\r\n".
"Referer://archives/7/"."\r\n",
'content' => $data,
],
];
$context = stream_context_create($opts);
$html = @file_get_contents('//archives/7/comment', false, $context);