卷曲发布数据并获得结果

This is my code :

<?php
$url = 'http://huaweiunlockcalculator.com/v201-huawei-unlock-calculator-v3';
$fields = array('imei' => $_POST['imei']);

//url-ify the data for the POST
$fields_string="";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, 'http://huaweiunlockcalculator.com/v201-huawei-unlock-calculator-v3');
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
$output=preg_match_all("/Unlock \(V[123]\): ([0-9]+)/",$result, $matches);
echo $matches[0];
//print_r($matches[0][2]);echo "<br>";
//print_r($matches[0][1]);echo "<br>";
//print_r($matches[0][0]);echo "<br>";

curl_close($ch);
//close connection

It brings a wrong result :( I need to send IMEI and get result in my own site. How can I do that ?

some web page need whole post data whether null of the value. A function called http_build_query() function can easily build a post or get query string , you just give a parameter type array .

$url =  "http://www.example.com/api/WalletVerification";
            $params = array();
            $inputs = array();
            $inputs['rid']=100;//$retailer_id;
            $inputs['merchantid']="B170127CT3D9H2XJAQUYF0L";
            $inputs['amount']=10;//$wallet_raminfo;
            $params =json_encode($inputs);

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $result = curl_exec($ch);
           curl_close($ch);
            $output=  json_decode($result);
         //  print_r($output);
         if($output->status=='000'){
             $raminfostrans_id= $output->transactionid;
             $payment_status=TRUE;
         }else{
              $payment_status=false;
              $failure_msg="insuffient balance";
         }