dthl8036 2016-07-03 05:00
浏览 30
已采纳

cURL到PHP等价

I am trying to correctly convert a cURL command to PHP, but I can't seem to find the correct commands. I can run this command with cURL but I need to run this through TROPO, and they only have a few script options.

So I am trying in PHP.

curl https://api.particle.io/v1/devices/310029000547353138383138/setNum \ -d access_token=e650d0dec0476de7d64b23110fed31dcb3cbxxxx \ -d args=2085555555

My try, what am I missing?

<?php
    function submitValue() {
      $ch = curl_init("https://api.particle.io/v1/devices/310029000547353138383138/setNum");
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, 'access_token=e650d0dec0476de7d64b23110fed31dcb3cbxxxx&"args=2085555555"');                                                                       
      );

      $output = curl_exec($ch);

      if (curl_getinfo($ch, CURLINFO_HTTP_CODE) != '200') {
        return null;
      }
      return $output;
    } 
?>
  • 写回答

1条回答 默认 最新

  • dounianji7883 2016-07-03 05:18
    关注

    Try to use cURL command below:

    curl --data "access_token=e650d0dec0476de7d64b23110fed31dcb3cbxxxx&args=2085555555" https://api.particle.io/v1/devices/310029000547353138383138/setNum
    

    Got this answer from https://superuser.com/a/149335

    UPDATED:

    Here I have provided PHP code:

    $data = json_decode(array(
          "access_token" => "e650d0dec0476de7d64b23110fed31dcb3cbxxxx",
          "args" => "2085555555"
    ));
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.particle.io/v1/devices/310029000547353138383138/setNum');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $output = curl_exec($ch);
    curl_close($ch);
    

    Hope this will help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵