在请求的主体中使用Curl将参数传递给API。
问题描述 投票:1回答:1
我将数据从一个表格发布到两个不同的APIS。第一台工作正常,但这台就不行了。
这就是我发送的内容,有一个连接到API,但参数没有到达,支持说,我必须发送数据在我的网站上。身体 的请求,但我不知道如何做。$chThree= curl_init();
// values API 3
$dataApiThree = array(
'cid' => '199',
'uid' => $_POST['uid'],
'f_3_firstname' => $_POST['firstname'],
'f_4_lastname' => $_POST['lastname'],
'f_1_email' => $_POST['email'],
'f_11_postcode' => $_POST['meta_Zip'],
'f_12_phone1' => $_POST['mobile_phone'],
'f_135_nombre_empresa' => $_POST['meta_empresa'],
'f_134_cantidad_vehiculos' => $_POST['meta_cantidadVehiculos'],
'f_133_tipo_servicio ' => $_POST['meta_Gestion']
);
$optsThree = array(
CURLOPT_URL => 'https://leadtowin.databowl.com/api/v1/lead',
CURLOPT_HTTPHEADER => 'Content-Type: application/x-www-form-urlencoded',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $dataApiThree,
CURLOPT_RETURNTRANSFER => false,
CURLOPT_REFERER => $_SERVER['HTTP_REFERER']
);
//end API 3
//curl API3
curl_setopt_array($chThree, $optsThree);
$responseThree = curl_exec($chThree);
$responseThree = json_decode($responseThree);
curl_close($chThree);
php
api
curl
1个回答
0
投票
我已经找到了答案,这是代码谁的工作。<?php
$post_array = array(
"cid" => "199",
"sid" => "2",
"uid" => $_POST['uid'],
"optin_email" => $_POST['optin_email'],
"optin_email_timestamp" => $_POST['optin_email_timestamp'],
"optin_phone" => $_POST['optin_phone'],
"optin_phone_timestamp" => $_POST['optin_phone_timestamp'],
"optin_sms" => $_POST['optin_sms'],
"optin_sms_timestamp" => $_POST['optin_sms_timestamp'],
"optin_postal" => $_POST['optin_postal'],
"optin_postal_timestamp" => $_POST['optin_postal_timestamp'],
"f_1_email" => $_POST['f_1_email'],
"f_3_firstname" => $_POST['f_3_firstname'],
"f_4_lastname" => $_POST['f_4_lastname'],
"f_11_postcode" => $_POST['f_11_postcode'],
"f_12_phone1" => $_POST['f_12_phone1'],
"f_135_nombre_empresa" => $_POST['f_135_nombre_empresa'],
"f_134_cantidad_vehiculos" => $_POST['f_134_cantidad_vehiculos'],
"f_133_tipo_servicio" => $_POST['f_133_tipo_servicio']
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://leadtowin.databowl.com/api/v1/lead",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query($post_array),
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded",
"Accept-Encoding: UTF-8",
"Content-Type: application/x-www-form-urlencoded",
"Cookie: PHPSESSID=d053646c7953d9116849a8aa4717ab81"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
热门问题