duanji6997 2019-05-10 22:10
浏览 161

cURL和file_get_contents都不能加载某些网页

I am running an IIS 8 / PHP web server and am attempting to write a so-called 'proxy script' as a means of fetching HTTP content and loading it onto an HTTPS page.

Although the script does run successfully (outputting whatever the HTTP page sends) in some cases - for example, Google.com, Amazon.com, etc. - it does not work in fetching my own website and a few others.

Here is the code of proxy.php:

<?php
$url = $_GET['url'];

echo "FETCHING URL<br/>";      // displays this no matter what URL I enter 
$ctx_array = array('http' =>
    array(
        'method' => 'GET',
        'timeout' => 10,
    )
);
$ctx = stream_context_create($ctx_array);
$output = file_get_contents($url, false, $output);  // times out for certain requests
echo $output;

When I set $_GET['url'] to http://www.ucomc.net, the script fails. With most other URLs, it works fine.

I have checked other answers on here and other places but none of them describe my issue, nor do the solutions offered solve it.

I've seen some suggestions to similar problems that involve changing the user agent, but when I do this it not only does not solve the existing problem but prevents other sites from loading as well. I do not want to rely on third-party proxies (don't trust the free ones/want to deal with their query limit and don't want to pay for the expensive ones)

  • 写回答

1条回答 默认 最新

  • doter1995 2019-05-11 20:45
    关注

    Turns out that it was just a problem with the firewall. Testing it on a PHP sandbox worked fine, so I just had to modify the outgoing connections settings in the server firewall to allow the request through.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?