服務器接收:php
<?php服務器
error_reporting(0);
function get_contents_input()
{
$data = file_get_contents('php://input'); //讀取文檔流中的數據
@ file_put_contents('./data/a.txt', $data); //寫入文件中
}
get_contents_input();
?>app
客服端請求: url
<?php
$data = file_get_contents('./data/b.txt');
$http_entity_body = $data;
$http_entity_type = 'application/x-www-form-urlencoded';
$http_entity_length = strlen($http_entity_body);
$host = '127.0.0.1';
$port = 8080;
$path = '/20160825/test13.php';
$fp = fsockopen($host, $port, $error_no, $error_desc, 30); //建立鏈接
if($fp)
{code
/**orm
* 發送頭信息文檔
*/
fputs($fp, "POST {$path} HTTP/1.1\r\n");
fputs($fp, "Host: {$host}\r\n");
fputs($fp, "Content-Type: {$http_entity_type}\r\n");
fputs($fp, "Content-Length: {$http_entity_length}\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $http_entity_body . "\r\n\r\n");
get
//讀取返回信息
while (!feof($fp)) {
$d .= fgets($fp, 4096);
}
fclose($fp);
echo $d;
}input
?>it