[英]how to put variable to array in curl
(I apologize in advance for my English at the carpet level) (我对在地毯上的英语表示歉意)
I want send request by curl, the code i use normal work. 我想通过curl发送请求,该代码我可以正常使用。 When i change my code adding variable in to array, code working, also dont set this cookie.
当我更改代码将变量添加到数组中时,代码正常工作,也不要设置此Cookie。
i tried set: 我试过了
'Cookie: ssid=.$input; path=/; domain=example.com;',
and 和
'Cookie: "ssid=".$input; path=/; domain=example.com;',
and 和
'Cookie: 'ssid='.$input; path=/; domain=example.com;',
this is all code 这就是全部代码
$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;',
),
));
i want this cake read from variable ($input) 我希望从变量($ input)中读取此蛋糕
Assign a variable to particular array 将变量分配给特定数组
$myArr['message']['to_recipients'] = $emails;
then set on curl 然后设置卷曲
$ch = curl_init();
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $myArr ));
you can send the cookie manually along with the cookie from the file(using cookie-file option). 您可以将cookie与文件中的cookie一起手动发送(使用cookie-file选项)。 For example:
例如:
//SEND DATA VARIABLE IN JSON ENCODED FORMAT
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $myArr ));
// sending manually set cookie
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: test=cookie"));
// sending cookies from file
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
And for you code you have used php variable in cookie as string so you have to update your script like given below. 对于您的代码,您已在cookie中使用php变量作为字符串,因此您必须像下面给出的那样更新脚本。
$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;',
),
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.