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;
?>
View Code

2.stream.php

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

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

posted on 2014-04-18 12:10  左小兵  阅读(581)  评论(0编辑  收藏  举报

导航