http协议传输二进制数据以及对输入流(php://input)和http请求的理解

1.index.php

<?php

$data=file_get_contents('./a.jpg');
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\n"
."Content-Length: " . strlen($data) . "\r\n",
// "Authorization: Basic ".base64_encode("$https_user:$https_password")."\r\n",
'content' => $data,
'timeout' => 60
)
); $context = stream_context_create($opts);
$url = 'http://127.0.0.1/testhttpstream/stream.php';
$result = file_get_contents($url, false, $context);
header('Content-type:image/jpg');
echo $result;
?>

2.stream.php

<?php
$data=file_get_contents('php://input');
echo $data;

3.http请求(除get请求)里也有正文,而不是只有请求头而已,php://input获取的就是请求里的正文.

上一篇:知方可补不足~Sqlserver发布订阅与sql事务的关系


下一篇:process vs thread