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 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
  • ¥15 栅极驱动低侧烧毁MOSFET
  • ¥30 写segy数据时出错3
  • ¥100 linux下qt运行QCefView demo报错
  • ¥50 F1C100S下的红外解码IR_RX驱动问题
  • ¥20 基于matlab的航迹融合 航迹关联 航迹插补
  • ¥15 用Matlab实现图中的光线追迹
  • ¥15 联想笔记本开机出现系统更新界面
  • ¥15 各位帮帮我 我不想重做系统
  • ¥30 微信小程序蓝牙数据透传