duanqiao1949 2016-03-10 17:00
浏览 28
已采纳

卷曲页面不起作用

I have this code to load external pages on my website:

<?php 
function curl($url){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
            $data = curl_exec($ch);
            curl_close($ch);
            return $data;
  }


  $url = 'http://rooster.csvincentvangogh.nl:8081';
  $contents = curl($url);
  echo $contents;
?>

It works for most sites, but not the one I need: http://rooster.csvincentvangogh.nl:8081. Is this because of the :8081? It needs to be there though, otherwise the site doesn't work... How could I fix this? Is there an alternative way, in stead of curl?

I tested it on http://portquiz.net. Ports such as 80 and 8080 work, but e.g. 8888 and 8081 not. http://rooster.csvincentvangogh.nl:8080 works too, but that has different directories and not the pages I need. I really do need the pages on :8081...

Thanks in advance!

  • 写回答

2条回答 默认 最新

  • doutang1946 2016-03-10 17:35
    关注

    i GUESS its because its detecting the 404 error and thus want to return an "error" (bool(false)?) to warn you, so it discards the body and ignores CURLOPT_RETURNTRANSFERS. anyway, use this.

    function curl($url,&$body){
                $ch = curl_init();
                $tmpfile=tmpfile();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch,CURLOPT_FILE,$tmpfile);
                curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
                $ret = curl_exec($ch);
                $body=file_get_contents ( stream_get_meta_data ($tmpfile) ['uri'] );
                curl_close($ch);
                fclose($tmpfile);
                return $ret;
      }
    

    also consider CURLOPT_STDERR with CURLOPT_VERBOSE to get detailed information about what curl is thinking ^^ (often very useful debug info when "it doesn't work")

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line