gpt4 book ai didi

php - 在 Curl 请求中传递参数

转载 作者:行者123 更新时间:2023-12-04 03:56:45 25 4
gpt4 key购买 nike

我已经尝试使用终端进行 curl 请求,它正在工作,但是当我将该 curl 请求转换为 php 代码时,一个传递的参数不起作用。

终端 curl 请求:

curl --insecure "https://www.zohoapis.in/phonebridge/v3/clicktodial" -X POST -d "clicktodialuri=$clicktodialurl&clicktodialparam=[{'name':'fromnumber','value':'555'}]&zohouser=123456" -H "Authorization: Zoho-oauthtoken 1000.aedb399e2389cfacef60f965af052cbf" -H "Content-Type: application/x-www-form-urlencoded"

响应:

{"message":"ASTPP Clicktodial functionality has been enabled","status":"success","code":"SUCCESS"}

PHP 代码:

$zohouser = '6000';

$access_token = '1000.c3c1107b635f1f5b257d831677e077d2';
$cURL = "https://www.zohoapis.in/phonebridge/v3/clicktodial?clicktodialuri=$click_to_dial&clicktodialparam=[{'name':'fromnumber','value':'555'}]&zohouser=$zohouser";


$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => $cURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"Authorization: Zoho-oauthtoken " . $access_token,
"Content-Type: application/x-www-form-urlencoded",
"cache-control: no-cache"
),
));

$response = json_decode(curl_exec($curl));

$err = curl_error($curl);
print_r($err);
curl_close($curl);
print_r($response);exit;

在运行此 php curl 请求期间未收到任何响应或错误。你能帮我如何在 php curl 请求中将字符串作为参数传递吗?

最佳答案

$strURL= "https://www.zohoapis.in/phonebridge/v3/clicktodial";


$arrHeader= array(
'Authorization:Zoho-oauthtoken 1000.aedb399e2389cfacef60f965af052cbf'
);

$params= array(

"clicktodialparam"=>"[{\"name\":\"fromnumber\",\"value\":\"555\"}]",
"authorizationparam"=>"{\"name\":\"X-Auth-Token\",\"value\":\"1000.aedb399e2389cfacef60f965af052cbf\"}",
"clicktodialuri" => "$click_to_dial",
"zohouser" => "123456"



);


$ch= curl_init();

curl_setopt_array($ch,array(
CURLOPT_URL =>$strURL,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => $arrHeader,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 0,
CURLOPT_TIMEOUT => 0,
CURLOPT_POSTFIELDS => http_build_query($params)


));


$strResponse= curl_exec($ch);

print_r($strResponse);

echo curl_error($ch);

关于php - 在 Curl 请求中传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63726089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com