通过PHP的cURL适用于某些网站,而其他一些网站则不起作用?

<?php
  $url = 'https://adidas.com/us/';
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_HEADER, false);
  $data = curl_exec($curl);
  curl_close($curl);
  echo $data;
?>

I'm just trying to display the contents via cURL, and when I try https://www.google.com/ or another website, it works just fine, however on the adidas site, it timesout?

Thanks!

adidas.com is apparently inaccessible through HTTPS. It works through HTTP and redirects to http://www.adidas.com/us/. This address works through HTTPS too.

Use https://www.adidas.com/us/ instead.

Add a curl_getinfo call and you'll see more useful information

<?php
  $url = 'https://adidas.com/us/';
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_HEADER, false);
  $data = curl_exec($curl);
  print_r(curl_getinfo($curl));
  curl_close($curl);
  echo $data;
?>

In this case, after a minute it times out and curl_getinfo returns http_code of 0. This means that a connection can not be established.

You get an empty string for curl_exec (for http link) because response code is 301 Moved Permanently. Body of the HTTP response is empty.