1

My curl PHP code:

$url = "";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

If $url is, for example, https://www.google.com then all is OK. But if $url is, for example, https://www.twitch.tv I cannot get answer, just getting:

504 error

What can be wrong?

Testikus
  • 11
  • 1
  • 3
  • Possible duplicate of [Setting Curl's Timeout in PHP](https://stackoverflow.com/questions/2582057/setting-curls-timeout-in-php) – Barry Oct 17 '18 at 16:12
  • Nope. Problem: do not conecting to several sites but to others connects. – Testikus Oct 17 '18 at 17:06
  • They might use some kind of user agent sniffing to deny (never respond) requests coming from `curl` and similar tools. You can try using a fake user agent header, and possibly add some other headers as well to get around this. In the chrome devtools network panel, you can right click a request and choose `copy as curl` to get a curl command which includes the same headers that chrome itself used for that request. There might be a similar feature in other browsers as well. – Håken Lid Oct 17 '18 at 17:10
  • I tried to use Discord Oauth that is why I'm trying to understand this. Discord Oauth shouldn't deny requests! So I don't think that your advice will help me. Update: Did not helped. – Testikus Oct 17 '18 at 17:13

2 Answers2

0

It is probably due to the redirection to the https site. Try using the url https://www.twitch.tv.

Gbzz
  • 1
  • That is how I wrote it in URL. Nothing changed. Added CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT but still cannot understand why it cannot read it for about 10 seconds: Resolving timed out after 10519 milliseconds – Testikus Oct 17 '18 at 16:59
0

It could your ip is Blacklisted try to use proxy and set SSL_VERIFYPEER to false :

$url = "https://www.twitch.tv";
$proxy='xxx.xxx.xxx.xxx:xxxx';
        $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $url);
       curl_setopt($ch,CURLOPT_PROXY,$proxy);
        curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch, CURLOPT_POST, true);


        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

$answer = curl_exec($ch);

print $answer;
HamzaNig
  • 1,019
  • 1
  • 10
  • 33