doujuanxun7167 2012-11-24 02:49
浏览 39

PHP cURL不会发送适当的标头

I'm trying to send some headers with cURL in PHP and the headers are not sending.

The code is:

$header = array('Referer: xxx',
        'Origin: xxx',
        'Content-Type: application/x-www-form-urlencoded',
        'Connection: keep-alive',
        'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3',
        'Cache-Control: max-age=0',
        'Except:');

and using this:

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$t = curl_exec($ch);

$sentHeaders = curl_getinfo($ch);

var_dump($sentHeaders);

and in the dump I didn't see Origin, content-type, referrer and nothing... I'm trying to send a POST and it isn't sending.

What I am doing wrong?

edited: Now POST isn't sending:

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_URL, $url);
$t = curl_exec($ch);
  • 写回答

2条回答 默认 最新

  • dqrdlqpo775594 2012-11-24 02:53
    关注

    Add this option to see the request headers in the getinfo call:

    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程