php获取微信头像缓慢,file_get_content无法正常下载微信头像解决方法

业务需要下载到微信头像到本地,先前一直使用file_get_content来下载,,忽然发现不行,返回的是false...

个人猜想要模拟真实点的才让下载..

直接来看代码(我是使用了YurunHttp这个类库):

YurunHttp下载地址:http://git.oschina.net/yurunsoft/YurunHttp

public function getUrlStr($url) {

tool()->classs("curl/HttpRequest");

tool()->classs("curl/HttpResponse");

$request = new \HttpRequest();

$response = $request

->header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")

->header("Accept-Encoding", "gzip, deflate, sdch")

->header("Accept-Language", "zh-CN,zh;q=0.8")

->header("Cache-Control:", "max-age=0")

->header("Connection", "keep-alive")

->header("Host", "wx.qlogo.cn")

->header("If-Modified-Since", "Fri, 07 Oct 2016 10:05:15 GMT")

->header("Referer", "http://www.baidu.com")

->header("Upgrade-Insecure-Requests", "1")

->header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36")

->get($url);

return $response->body;

}

模拟之后,终于返回到他的头像回来了

c662d51e5ce98e1c018be845c7f0820b.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值