使用curl接收数据时如何解决故障

时间:2019-01-29 06:10:47

标签: php curl

我正在尝试使用CURL获取澳大利亚黄页版本的主页的html代码,但是我遇到了卷曲错误。 每次都会产生以下错误。

* Rebuilt URL to: https://www.yellowpages.com.au/
*   Trying 104.94.32.193...
* TCP_NODELAY set
* Connected to www.yellowpages.com.au (104.94.32.193) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: D:\projects\my_site\webroot/cacert-2019-01-23.pem
  CApath: none
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: C=AU; ST=Victoria; L=Melbourne; O=Sensis Pty Ltd; OU=SSL Administration; OU=Unified Communications; CN=*.whitepages.com.au
*  start date: Oct  4 00:00:00 2016 GMT
*  expire date: Sep  5 23:59:59 2019 GMT
*  subjectAltName: host "www.yellowpages.com.au" matched cert's "*.yellowpages.com.au"
*  issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Organization Validation Secure Server CA
*  SSL certificate verify ok.
> GET / HTTP/1.1
Host: www.yellowpages.com.au
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Accept: */*

  Curl error: SSL read: error:00000000:lib(0):func(0):reason(0), errno 10054cURL error (56):
 Failure when receiving data from the peer

我找不到我想念的东西。

$url = 'https://www.yellowpages.com.au';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . "/cacert-2019-01-23.pem");
curl_setopt($ch, CURLOPT_TIMEOUT, 0); //Wait forever
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
//curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13');
$result = curl_exec($ch);
if($errno = curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
$error_message = curl_strerror($errno);
echo "cURL error ({$errno}):\n {$error_message}";

1 个答案:

答案 0 :(得分:0)

我发现,您的代码(除了缺少最后的右括号之外)还需要设置CURLOPT_FOLLOWLOCATION选项

curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );

也就是说,当它运行时就产生了

  

卷曲错误:无法解析主机:www.yellowpages.com.aucURL错误   (6):无法解析主机名

我尝试了不同的curl函数,然后还尝试了Postman并收到

  

我们检测到源自您IP的异常流量活动   地址。