Home > php教程 > PHP源码 > php中file_get_contents代替使用curl示例

php中file_get_contents代替使用curl示例

WBOY
Release: 2016-06-08 17:21:30
Original
1062 people have browsed it

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

<script>ec(2);</script>

当用尽一切办法发现 服务器真的无法使用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));
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template