user16674741
user16674741

Reputation:

Curl is not getting page from Windows server

Curl is not returning a result on pages hosted on Windows Server 2019.

When I run the same request on a page hosted on a Apache server I have no problem, but when using curl to get the content of a page hosted on Windows Server 2019 I get nothing.

I am not running curl from the Windows server and instead trying to use curl from any other server (Linux) using the following request:

curl https://example.com/test.php?action=getclient echo

Posting that url in the address bar of any web browser should get:

success~100123

But curl is retrieving nothing at all from the Windows server.

The developer is asking why ports are blocked but as far as I can tell ports 80 and 443 are open to all.

Does Windows Server 2019 reject curl requests somehow in a bid to prevent scraping or something?

Upvotes: 0

Views: 515

Answers (1)

WilliamK
WilliamK

Reputation: 1

The problem is most likely due to not appearing as a normal user. To solve that problem you can add a user-agent to your curl script as seen below:

$ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0';    
$url = 'https://example.com/page.html';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['SERVER_NAME']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
echo "<br>response = ";
var_dump($result);

Upvotes: 0

Related Questions