php采用file_get_contents代替使用curl实例
本文实例讲述了php采用file_get_contents代替使用curl的方法,分享给大家供大家参考。具体实现方法如下:
file_get_contents代替使用curl其实不多见了,但有时你碰到服务器不支持curl时我们可以使用file_get_contents代替使用curl,下面看个例子。
当用尽一切办法发现服务器真的无法使用curl时。或者curl不支持https时。curlhttps出现502时。你又不想重装网站环境的时候,你就改用file_get_contents代替吧。
curl经常使用的curlgetcurlpost
curlget替代直接用file_get_contents($url)就可以了
curlpost替代如下:
functionPost($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
)
);
returnfile_get_contents($url,false,stream_context_create($options));
}
希望本文所述对大家的php程序设计有所帮助。
热门推荐
10 致敬大国工匠祝福语简短
11 送病人简短的祝福语
12 每年春节祝福语大全简短
13 爸爸生日的祝福语简短
14 结婚伴娘祝福语简短精辟
15 感谢教官文案祝福语简短
16 调皮祝福语老师文案简短
17 朝鲜元旦祝福语大全简短
18 送姐姐的话祝福语简短