码迷,mamicode.com
首页 > 其他好文 > 详细

fopen 模拟 post 提交

时间:2015-06-11 09:39:54      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

function do_post_request($url, $data, $optional_headers = null){
        $params = array(‘http‘ => array(
            ‘method‘ => ‘POST‘,
            ‘content‘ => $data
        ));
        if ($optional_headers !== null) {
            $params[‘http‘][‘header‘] = $optional_headers;
        }
        $ctx = stream_context_create($params);
        $fp = @fopen($url, ‘rb‘, false, $ctx);
        if (!$fp) {
            throw new Exception("Problem with $url, $php_errormsg");
        }
        $response = @stream_get_contents($fp);
        if ($response === false) {
            throw new Exception("Problem reading data from $url, $php_errormsg");
        }
        return $response;
    }

fopen 模拟 post 提交

标签:

原文地址:http://my.oschina.net/u/2269208/blog/465389

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!