手机
当前位置:查字典教程网 >编程开发 >php教程 >php采用file_get_contents代替使用curl实例
php采用file_get_contents代替使用curl实例
摘要:本文实例讲述了php采用file_get_contents代替使用curl的方法,分享给大家供大家参考。具体实现方法如下:file_get_...

本文实例讲述了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采用file_get_contents代替使用curl实例】相关文章:

php使用curl打开https网站的方法

PHP file_get_contents函数读取远程数据超时的解决方法

php中file_exists函数使用详解

php生成zip文件类实例

php自定义hash函数实例

php计算给定时间之前的函数用法实例

PHP中的事务使用实例

php使用GD实现颜色渐变实例

PHP SPL标准库之SplFixedArray使用实例

PHP 双链表(SplDoublyLinkedList)简介和使用实例

精品推荐
分类导航