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 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试