dongyo1959 2017-02-02 15:12
浏览 17
已采纳

PHP中的cURL请求

I have a question regarding cURL requests in PHP. I have to use cURL requests but haven't been in touch with them at all.

In the following example I will show you how I see the cURL request. My question is: How do I "convert" this statement into a PHP cURL request?

curl -X GET --header "Accept: application/json" --header "Authorization: Bearer APIKEY" "https://api.example.com/api-api-ng/v1/function?lat=50&lon=8&radius=500&statement=2"

So I hope you guys can help me with this problem. I only know the basics of cURL and hope you can show me all steps required to set up a cURL request.

  • 写回答

1条回答 默认 最新

  • douhui5953 2017-02-02 15:20
    关注
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, "https://api.example.com/api-api-ng/v1/function?lat=50&lon=8&radius=500&statement=2");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    
    
    $headers = array();
    $headers[] = "Accept: application/json";
    $headers[] = "Authorization: Bearer APIKEY";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);
    echo $result;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分