php采用file_get_contents代替使用curl php采用file_get_contents代替使用curl实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

php采用file_get_contents代替使用curl php采用file_get_contents代替使用curl实例

  2021-03-19 我要评论
想了解php采用file_get_contents代替使用curl实例的相关内容吗,在本文为您仔细讲解php采用file_get_contents代替使用curl的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:php,file_get_contents,代替,curl,下面大家一起来学习吧。

本文实例讲述了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));
}

希望本文所述对大家的php程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们