【问题标题】:Curl is not getting page from Windows serverCurl 没有从 Windows 服务器获取页面
【发布时间】:2022-08-10 00:52:47
【问题描述】:

Curl 未在 Windows Server 2019 上托管的页面上返回结果。

当我在托管在 Apache 服务器上的页面上运行相同的请求时,我没有问题,但是当使用 curl 获取托管在 Windows Server 2019 上的页面的内容时,我什么也得不到。

我没有从 Windows 服务器运行 curl,而是尝试使用以下请求从任何其他服务器(Linux)使用 curl:

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

在任何网络浏览器的地址栏中发布该 url 应该得到:

success~100123

但是 curl 根本没有从 Windows 服务器中检索任何内容。

开发人员询问为什么端口被阻止,但据我所知,端口 80 和 443 对所有人开放。

Windows Server 2019 是否以某种方式拒绝 curl 以防止刮擦或其他什么?

    标签: php-curl windows-server-2019


    【解决方案1】:

    该问题很可能是由于没有以普通用户的身份出现。要解决该问题,您可以在 curl 脚本中添加用户代理,如下所示:

    $userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';    
    $url = 'https://example.com/page.html';
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多