php采用file_get_contents代替使用curl实例
网络编程 2021-07-05 09:50www.168986.cn编程入门
这篇文章主要介绍了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,狼蚁网站SEO优化看个例子。
当用尽一切办法发现 服务器真的无法使用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));
}
$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程序设计有所帮助。
编程语言
- socket网络编程 socket网络编程Socket基础
- 少儿编程培训班 少儿编程培训班教学方法
- linux系统编程:Linux系统编程多线程基础
- unix环境高级编程 首发于 UNIX环境高级编程学习之
- 学编程学哪一种比较好 初学者哪种编程语言比较
- 学PLC编程学费多少
- 计算机编程入门 学计算机编程入门的初学指南
- 世界编程语言排行榜
- vba编程培训:Excel VBA编程培训初学者教程
- 少儿编程课程:少儿编程学什么及各年龄段如何
- 游戏编程入门:少儿游戏编程入门的技巧
- 学编程哪个培训机构好 编程培训机构哪个好
- 编程机器人加盟 机器人编程加盟哪家好
- 在线少儿编程机构排名
- 电脑编程入门自学
- 服务器系统下载:服务器系统的安装