教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php中file_get_contents代替使用curl示例

php中file_get_contents代替使用curl示例

发布时间:2016-10-18   编辑:jiaochengji.com
教程集为您提供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 替代:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7950')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7950>

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中file_get_contents代替使用curl示例
php file_get_contents函数抓取页面信息的代码
php 获取远程网页内容简单函数
PHP fopen/file_get_contents与curl性能比较
php中curl、fsocket、file_get_content函数比较
php读取远程文件的三种方法分享
php下载css中图片函数
php获取网页标题的三种方法示例
PHP模拟POST提交的示例代码
php中file_get_contents和curl两个函数用法

[关闭]
~ ~