dtstnjl898781429 2016-07-07 23:26
浏览 116

PHP使用GET参数从外部URL获取内容

I copied this code from another question here on stack..

   $fbid = '666666666';
    $url = 'http://www.example.de/v/fffff.php'; // work
    $url = 'http://www.example.de/v/fffff.php?fbid=' . $fbid; // not working, page don't load

    curl_setopt_array($curl, array(
      CURLOPT_URL => $url,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "GET",
      CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache"
      ),
    ));

    $antwort = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

Anyone idea how to get the contents from url with GET parameters?

  • 写回答

1条回答 默认 最新

  • douyong1886 2016-07-08 00:20
    关注

    You are missing the . that concatenates $fbid to the url. And you need to instantiate the curl first as well. Change your code to:

            $fbid = 123;// as sample dbid
            $url = 'http://www.example.de/v/fffff.php'; // work
            $url = 'http://www.example.de/v/fffff.php?fbid='.$fbid; // not working, page don't load
    
            $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "GET",
        CURLOPT_HTTPHEADER => array(
            "cache-control: no-cache"
        ),
    ));
    
    $antwort = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题