使用cURL将POST数据发送到API [关闭]

I can send sms using the following form

<form action="http://myserviceprovider/myname/server.php" method="post"> 
 <input  type="hidden" value="MyUsername" name="user" />   
 <input  type="hidden" value="MyPassword" name="pass" />           
 <input  type="hidden" value="MyKey" name="sid" />    
 <input  type="hidden" value="12345678" name="sms[0][0]" /> 
 <input  type="hidden" value="MyFrist SMS Text" name="sms[0][1]" />
 <input  type="hidden" value="97654321" name="sms[1][0]" />                    
 <input  type="hidden" value="MySecond SMS Text" name="sms[1][1]" />
 <input type="submit" />
</form> 

Now I am trying to send sms using PHP cURL. I have created an array which contains cellphone numbers and messages:

$sms =array(
           array("0" => "12345678", "1" => "MyFrist SMS Text"),
           array("0" => "97654321", "1" => "MySecond SMS Text")
      );

The problem is I cannot figure out how exactly to send the values including username,password and Mykey using the following

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
curl_exec($ch);

Could you please tell how to solve this problem?

As far as I undersand you would want to post to the FORM URL with cURL, instead of using the site. You need to send the other form fields as well as the sms information, i.e you need to pass to the form url your Username, Password, Sid.

An example script could look like this:

<?php
define('SMS_SERVICE_URL', 'http://myserviceprovider/myname/server.php');
define('USERNAME', 'YOUR_USERNAME_HERE');
define('PASSWORD', 'YOUR_PASSWORD_HERE');
define('KEY', 'YOUR_KEY/SID_HERE');

$sms =array(
           array("0" => "12345678", "1" => "MyFrist SMS Text"),
           array("0" => "97654321", "1" => "MySecond SMS Text")
);


$post = array(
        'user' => USERNAME,
        'pass' => PASSWORD,
        'sid'  => KEY,
        'sms'  => $sms,
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, SMS_SERVICE_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec ($ch);

curl_close ($ch);
?>

To send your data as POST using curl, you need to tell curl you want post by setting CURLOPT_POST to true. Then you need to pass your data - put it into array like array('user'=>'<USERNAME>', ....); and pass this array to curl using CURLOPT_POSTFIELDS.