php采用file_get_contents代替使用curl实例

yipeiwu_com5年前PHP代码库

本文实例讲述了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程序设计有所帮助。

相关文章

php设计模式 Prototype (原型模式)代码

复制代码 代码如下:<?php /** * 原型模式 * * 用原型实例指定创建对象的种类.并且通过拷贝这个原型来创建新的对象 * */ abstract class Protot...

PHP实现的ID混淆算法类与用法示例

本文实例讲述了PHP实现的ID混淆算法类与用法。分享给大家供大家参考,具体如下: <?php /** * ID混淆算法 */ class IdCrypt { /...

浅谈PDO的rowCount函数

PDO有一个函数PDOStatement::rowCount返回上一个SQL语句影响的行数。 rowCount函数对于DELETE, INSERT, 或者UPDATE语句的结果是正确的,...

解析zend studio中直接导入svn中的项目的方法步骤

1.在zend-studio中的项目explorer中右键-》import->选择svn->project from svn-》next-》选择create new ...l...

php中的数组操作函数整理

Array([key =>] value, [key =>] value, [key =>] value, [key =>] value) // key 可以是...