php中file_get_contents代替使用curl示例
发布时间:2022-06-16 09:31:57 所属栏目:PHP教程 来源:互联网
导读:file_get_contents代替使用curl其实不多见了,但有时你碰到服务器不支持curl时我们可以使用file_get_contents代替使用curl了,下面看个例子. 当用尽一切办法发现 服务器真的无法使用curl时,或者curl不支持https时,curl https 出现502时,你又不想重装网站环境.
|
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( //开源软件:phpfensi.com 'http' => array( 'method' => 'POST', 'header' =>"Content-type: application/x-www-form-urlencoded", 'content' => $post ) ); return file_get_contents($url, false, stream_context_create($options)); } (编辑:信阳站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |

