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 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存