【问题标题】:Sending multiple headers with curl request使用 curl 请求发送多个标头
【发布时间】:2020-02-28 09:54:07
【问题描述】:

大家好,我在 curl 请求中遇到了一个问题,我必须在其中发送很多信息或标头。我必须设置

用户代理
Sso 令牌
订阅者 ID
lbcookie
Channel id
Srno
Unique id
Appkey
Os 版本
操作系统类型
设备类型
设备密钥
版本 代码
语言 id
用户组
主机
连接
接受 编码

我必须发送一个我发送的获取请求,但它会发送并返回无法处理请求或没有数据的空白页面。

提前致谢 PHP初学者

【问题讨论】:

  • 请提供有关您的问题的更多信息。你如何发送 CURL 请求?使用终端?还是浏览器?或任何其他方式?说明您发送请求的确切方式。
  • 使用浏览器发送请求
  • 如何使用浏览器发送 CURL 请求,您只是从浏览器发送 GET HTTP 请求。

标签: php curl get header


【解决方案1】:

将您的标头添加到 $customHeaders 数组中,看看是否可行:

//The URL you're sending the request to.
$url = 'https://www.example.comp';

//Create a cURL handle.
$ch = curl_init($url);

//Create an array of custom headers.
$customHeaders = array(
    'Accept-Encoding: gzip, deflate, br',
    'Cookie: PHPSESSID=ciqas3vp82m514iubpr1b0md3o;',
    'Referer: https://www.google.com/',
    // add the headers you want to send as such
);

//Use the CURLOPT_HTTPHEADER option to use the custom headers.
curl_setopt($ch, CURLOPT_HTTPHEADER, $customHeaders);

//Execute the request
curl_exec($ch);   

更多详情请参考curl_setopt的文档

【讨论】:

    猜你喜欢
    • 2012-01-13
    • 2013-08-13
    • 2016-11-10
    • 1970-01-01
    • 2010-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-25
    相关资源
    最近更新 更多