1.index.php
<?php $data=file_get_contents('./a.jpg'); $opts = array('http' => array( 'method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded " ."Content-Length: " . strlen($data) . " ", // "Authorization: Basic ".base64_encode("$https_user:$https_password")." ", '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获取的就是请求里的正文.