Trouble converting POST curl from command line to php

前端 未结 2 1644
执笔经年
执笔经年 2021-01-24 21:13

I am having trouble converting my curl command into php.

This part works great.

CURL command that adds an entry into my Parse.com database:

curl          


        
2条回答
  •  隐瞒了意图╮
    2021-01-24 21:27

    Since you are doing a POST request you need to tell Curl to do that as well:

    $postData = '{"SiteID":"foundID","dataUsedString":"foundUsage","usageDate":"foundDate", "monthString":"foundMonth", "dayString":"foundDay","yearString":"foundYear"}';
    
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    

    You may also need to supply a Content-Length header:

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'X-Parse-Application-Id: my_id',
      'X-Parse-REST-API-Key: api_id',
      'Content-Type: application/json',                                                           
      'Content-Length: '.strlen($postData))                                                                       
    );
    

提交回复
热议问题