首页 > 代码库 > Curl发送header头信息
Curl发送header头信息
有些接口用CURL调用的时候,要发送header头信息
如百度的查询快递的接口
PHP代码如下:
$url = "https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?appid=4001&com={$type}&nu={$deliveryBn}"; $headers = array( "Host: sp0.baidu.com", "Connection: keep-alive", "Cache-Control: max-age=0", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36", "Accept-Encoding: gzip, deflate, sdch", "Accept-Language: zh-CN,zh;q=0.8", "Cookie: BAIDUID=FAFE6A61C5C95A71A482ABC3315F9228:FG=1; BIDUPSID=FAFE6A61C5C95A71A482ABC3315F9228; PSTM=1435563408; BD_UPN=12314653 "); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $output = curl_exec($ch); curl_close($ch); $arr = json_decode($output, true) /** $type是快递公司的代码简称,如:yuantong,shentong,ems,shunfeng,yunda,zhongtong,tiantian,debang,zhaijisong等 $deliveryBn则是运单号 **/
本文出自 “chensir” 博客,请务必保留此出处http://sourliki.blog.51cto.com/4838492/1949034
Curl发送header头信息
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。