我陷入了这样一个困境:简单的 URL 在浏览器和邮递员中工作正常,但在从 PHP 代码调用的 Curl 中却不起作用。我不知道出了什么问题。甚至邮递员生成的 php 代码也不起作用。
我的示例 URL 如下所示
https://example.com/WebService/visitorinput.asmx/AddVisitor?CallFromNumber=987xxxxxxx&CallToNumber=886xxxxxxx&CallDateTime=2024-01-10%2018%3A32%3A10&CallType=Missed%20Call&Notes=This%20is%20test%20entry
虽然生成的邮递员代码是
<?php
$variables = array(
"CallFromNumber" => "987xxxxxxx",
"CallToNumber" => "886xxxxxxx",
"CallDateTime" => "2024-01-10 18:32:10",
"CallType" => "Missed Call",
"Notes" => "This is test entry",
);
$curl = curl_init();
$url = 'https://example.com/WebService/visitorinput.asmx/AddVisitor?'. http_build_query( $variables ) ;
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => 'gzip, deflate, br', // Either I add or not result is same
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => [ // Tried to add this header but its same as before
'Content-Type: application/x-www-form-urlencoded',
]
));
$response = curl_exec($curl);
url_close($curl);
echo $response;
请求的 URL 是由另一个团队提供的 Web 服务,该团队构建在 ASP.net 中并在 Postman 中工作。在 Curl 中,我收到“403 - 禁止:访问被拒绝”。而在 Postman 中,它是一个 json 响应
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);