'CURLE_URL_MALFORMAT' 但所有语法似乎都没有问题
'CURLE_URL_MALFORMAT' but all the syntax seems to be ok
我对 cUrl 有疑问。最近,我发现问题出在 curl 的语法上,因为当我转储我想要执行的请求并将其放入 PostMan 时它可以工作,但是我的代码中的函数没有 returns 3 :'CURLE_URL_MALFORMAT'。有关信息,我的 curl 版本是 7.79.1
我尝试了 CURLOPT_RETURNTRANSFER、CURLOPT_POST 等一些不同的方法,但没有用...
这是我的函数:
private function cUrl_CreateContactFastFood($merchant_token, $arr)
{
$status = "active";
$Contact_name = $arr["customerName"];
$Contact_email = '';
if($Contact_email=='') {
$Contact_email= 'FastFoodCustomer@ttt.com';
}
$Contact_phone = $arr["phoneNumber"];
$Contact_address = $arr["endAddressResolved"];
$url = 'http://dostavka-bg.com/api_services/insert_contact';
$curl_params = '?keys=f74192da825962d3b1c2b2aa616ab68b&merchant_token='.$merchant_token.'&name='.$Contact_name.'&email='.$Contact_email.'&phone='.$Contact_phone.'&address='.$Contact_address.'&status='.$status;
$ch = curl_init();
$headers = array(
'Accept: */*',
'User-Agent: ',
'Accept-Encoding: gzip, deflate, br',
'Host: dostavka-bg.com',
'Connection: keep-alive'
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url.$curl_params);
$data = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
}
这是已解决的问题:
private function cUrl_CreateContactFastFood($merchant_token, $arr)
{
$status = "active";
$Contact_name = $arr["customerName"];
$Contact_email = '';//$arr["customer"]["invoicing_details"]["company_address"];
if($Contact_email==''){
$Contact_email= 'FastFoodCustomer@ttt.com';
}
$Contact_phone = $arr["phoneNumber"];
$Contact_address = $arr["endAddressResolved"];
$url = 'http://dostavka-bg.com/api_services/insert_contact';
$curl_params = '?keys=f74192da825962d3b1c2b2aa616ab68b&merchant_token='.urlencode($merchant_token).'&name='.urlencode($Contact_name).
'&email='.urlencode($Contact_email).'&phone='.urlencode($Contact_phone).'&address='.urlencode($Contact_address).'&status='.urlencode($status);
$ch = curl_init();
$headers = array(
'Accept: */*',
'User-Agent: ',
'Accept-Encoding: gzip, deflate, br',
'Host: dostavka-bg.com',
'Connection: keep-alive'
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url.$curl_params);
curl_setopt($ch, CURLOPT_POST, 1);
$data = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
$info = curl_version();
curl_close($ch);
return true;
}
您传递的 URL 包括几个查询字符串参数,您的示例中只显示了其中一些参数,但其中一些可能包含标点符号或 [=20 中不允许的其他字符=]秒。这些需要通过以下任一方式正确编码:
- 在构建查询字符串时对每个参数调用 urlencode or rawurlencode。
- 使用 http_build_query 为您全部格式化,而不是手动连接各个部分。
我对 cUrl 有疑问。最近,我发现问题出在 curl 的语法上,因为当我转储我想要执行的请求并将其放入 PostMan 时它可以工作,但是我的代码中的函数没有 returns 3 :'CURLE_URL_MALFORMAT'。有关信息,我的 curl 版本是 7.79.1
我尝试了 CURLOPT_RETURNTRANSFER、CURLOPT_POST 等一些不同的方法,但没有用...
这是我的函数:
private function cUrl_CreateContactFastFood($merchant_token, $arr)
{
$status = "active";
$Contact_name = $arr["customerName"];
$Contact_email = '';
if($Contact_email=='') {
$Contact_email= 'FastFoodCustomer@ttt.com';
}
$Contact_phone = $arr["phoneNumber"];
$Contact_address = $arr["endAddressResolved"];
$url = 'http://dostavka-bg.com/api_services/insert_contact';
$curl_params = '?keys=f74192da825962d3b1c2b2aa616ab68b&merchant_token='.$merchant_token.'&name='.$Contact_name.'&email='.$Contact_email.'&phone='.$Contact_phone.'&address='.$Contact_address.'&status='.$status;
$ch = curl_init();
$headers = array(
'Accept: */*',
'User-Agent: ',
'Accept-Encoding: gzip, deflate, br',
'Host: dostavka-bg.com',
'Connection: keep-alive'
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url.$curl_params);
$data = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
}
这是已解决的问题:
private function cUrl_CreateContactFastFood($merchant_token, $arr)
{
$status = "active";
$Contact_name = $arr["customerName"];
$Contact_email = '';//$arr["customer"]["invoicing_details"]["company_address"];
if($Contact_email==''){
$Contact_email= 'FastFoodCustomer@ttt.com';
}
$Contact_phone = $arr["phoneNumber"];
$Contact_address = $arr["endAddressResolved"];
$url = 'http://dostavka-bg.com/api_services/insert_contact';
$curl_params = '?keys=f74192da825962d3b1c2b2aa616ab68b&merchant_token='.urlencode($merchant_token).'&name='.urlencode($Contact_name).
'&email='.urlencode($Contact_email).'&phone='.urlencode($Contact_phone).'&address='.urlencode($Contact_address).'&status='.urlencode($status);
$ch = curl_init();
$headers = array(
'Accept: */*',
'User-Agent: ',
'Accept-Encoding: gzip, deflate, br',
'Host: dostavka-bg.com',
'Connection: keep-alive'
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url.$curl_params);
curl_setopt($ch, CURLOPT_POST, 1);
$data = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
$info = curl_version();
curl_close($ch);
return true;
}
您传递的 URL 包括几个查询字符串参数,您的示例中只显示了其中一些参数,但其中一些可能包含标点符号或 [=20 中不允许的其他字符=]秒。这些需要通过以下任一方式正确编码:
- 在构建查询字符串时对每个参数调用 urlencode or rawurlencode。
- 使用 http_build_query 为您全部格式化,而不是手动连接各个部分。