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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作