php采用file_get_contents代替使用curl实例
2015-01-24信息快讯网
这篇文章主要介绍了php采用file_get_contents代替使用curl的方法,实例讲述了file_get_contents模拟curl的post方法,对于服务器不支持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程序设计有所帮助。
php使用正则表达式获取图片url的方法
php使用CURL伪造IP和来源实例详解
ucenter通信原理分析
CI框架中site_url()和base_url()的区别
PHP中使用CURL获取页面title例子
Thinkphp中的curd应用实用要点
php读取mssql的ntext字段返回值为空的解决方法
关于URL最大长度限制的相关资料查证
CentOS6.5 编译安装lnmp环境
PHP中使用file_get_contents抓取网页中文乱码问题解决方法
php中get_meta_tags()、CURL与user-agent用法分析
php实现把url转换迅雷thunder资源下载地址的方法
php采用curl模仿登录人人网发布动态的方法
PHP采用curl模仿用户登陆新浪微博发微博的方法
php的curl封装类用法实例
PHP读取CURL模拟登录时生成Cookie文件的方法
CI框架安全类Security.php源码分析
PHP has encountered a Stack overflow问题解决方法
php之curl设置超时实例
php中count获取多维数组长度的方法
PHP中echo,print_r与var_dump区别分析
PHP错误Warning: Cannot modify header information - headers already sent by解决方法
PHP中file_get_contents高用法实例