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 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式
  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案
  • ¥15 matlab提取运动物体的坐标