首页 > 其他 > 详细

fopen 模拟 post 提交

时间:2015-06-11 09:38:16      阅读:219      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!