php - 如何将变量放入curl中的数组
问题描述
(我在地毯级别为我的英语提前道歉)
我想通过 curl 发送请求,我使用正常工作的代码。当我更改将变量添加到数组中的代码时,代码正常工作,也不要设置此 cookie。
我试过设置:
'Cookie: ssid=.$input; path=/; domain=example.com;',
和
'Cookie: "ssid=".$input; path=/; domain=example.com;',
和
'Cookie: 'ssid='.$input; path=/; domain=example.com;',
这是所有代码
$ch4=curl_init("https://example.com/");
curl_setopt_array($ch4,array(
CURLOPT_USERAGENT=>' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
CURLOPT_ENCODING=>'gzip, deflate',
CURLOPT_HTTPHEADER=>array(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: en-US,en;q=0.5',
'Accept-Encoding: gzip, deflate',
'Connection: keep-alive',
'Upgrade-Insecure-Requests: 1',
'Cookie: ssid=.$input; path=/; domain=example.com;',
),
));
我想从变量($input)中读取这个蛋糕
解决方案
将变量分配给特定数组
$myArr['message']['to_recipients'] = $emails;
然后设置卷曲
$ch = curl_init();
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $myArr ));
推荐阅读
- python - Python Scrapy text() 函数无法获取空的 td 元素
- mongodb - 使用 Mongoose 初始化和保存后,MongoDB 文档中缺少属性
- jspdf-autotable - 正文内容中的 HTML JSPDF AUTOTABLE
- css - SCSS 是带有“一些小例外”的 CSS 的超集——它们是什么?
- python - 使用掩码在向量化方程 numpy 之间进行选择
- php - class_existst 返回 false WP 插件开发
- java - 如何让任务等待另一个并发
- javascript - 尝试将 iOS 本机框架移植到 NativeScript
- google-tag-manager - 一个页面上有多个容器的 Google 跟踪代码管理器问题
- kotlin - BottomAppBar + NavigationView + FloatingActionButton + 导航组件 KOTLIN