首页 > 解决方案 > 如何将变量放入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)中读取这个蛋糕

标签: phpcurl

解决方案


将变量分配给特定数组

$myArr['message']['to_recipients'] = $emails;

然后设置卷曲

$ch = curl_init();
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $myArr ));

推荐阅读