博客列表 >php采用file_get_contents代替使用curl实例

php采用file_get_contents代替使用curl实例

书声的博客
书声的博客原创
2018年05月25日 10:00:191609浏览

本文实例讲述了php采用file_get_contents代替使用curl的方法,分享给大家供大家参考。具体实现方法如下:

file_get_contents代替使用curl其实不多见了,但有时你碰到服务器不支持curl时我们可以使用file_get_contents代替使用curl,下面看个例子。

当用尽一切办法发现 服务器真的无法使用curl时。或者curl不支持https时。curl https 出现502时。你又不想重装网站环境的时候,你就改用file_get_contents 代替吧。
curl 经常使用的 curl get curl post
curl get 替代 直接用file_get_contents($url) 就可以了
curl post 替代如下:

function Post($url, $post = null) {       
            $content = http_build_query($post);
            $content_length = strlen($content);
            $options = array(
                'http' => array(
                    'method' => 'POST',
                    'header' =>"Content-type: application/x-www-form-urlencoded",
                    'content' => $post
                )
            );
            return file_get_contents($url, false, stream_context_create($options));
    }

   

 原文链接:http://www.php.cn/write/3788.html   如有侵权,告知删除

 

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议