【发布时间】:2019-08-11 08:48:35
【问题描述】:
我目前正在尝试使用来自此link 的 curl 请求获取一些数据。 这样做会返回以下内容:
“HTTP/2 403 服务器:AkamaiGHost mime-version:1.0 内容类型:text/html 内容长度:293 过期时间:2019 年 8 月 11 日星期日 08:34:24 GMT 日期:2019 年 8 月 11 日 08 日星期日:格林威治标准时间 34:24
访问被拒绝
您没有访问“http://www.g2a.com/lucene/search/filter”的权限?在这台服务器上。
参考 #18.9d0c1502.1565512464.22e1446"
我知道 curl 可以正常工作,因为它可以与其他请求一起使用,只是这个请求被拒绝了。 另外,使用浏览器打开链接不会显示“拒绝访问”错误,但实际上会返回我需要的数据。
这是从代码中复制粘贴的 curl 请求:
try{
// initiate curl (used to request data from other webpages)
$ch = curl_init();
// will return the response, if false it prints the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// set the url, eliminates headers from response
curl_setopt($ch, CURLOPT_URL, $g2a);
curl_setopt($ch, CURLOPT_HEADER, true);
// execute
$result=curl_exec($ch);
//if some error occurs
if (!$result)
throw new Exception(curl_error($ch), curl_errno($ch));
// Closing
curl_close($ch);
} catch(Exception $e) {
trigger_error(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);
}
var_dump($result);
//converts json to associative array
$result=json_decode($result, true);
关于可能是什么问题的任何想法?
【问题讨论】:
-
您必须做一些特殊的事情来执行 HTTPS cURL 请求。尤其是
CURLOPT_SSL_VERIFYPEER选项。见:stackoverflow.com/a/4372730/3986005 -
$g2a 的实际价值是多少?