将数据从Android App发布到Backend PHP

时间:2017-06-10 09:54:57

标签: php android

如果我为变量赋值并将其传递给url,它就可以正常工作。

$waybill=508518;
$url = 'http://api.ecomexpress.in/track_me/api/mawbd/?awb='.$waybill.'&order=&username=cs@subhashreeinfotech.com&password=@@@@';
$ch = curl_init();                    // initiate curl
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the output in     string format
$output = curl_exec ($ch);

但我需要的是,我必须从Android应用程序动态获取运单号码。因为我将运单价值发布到后端的PHP代码,如下所示。但它无法正常工作

$waybill=$_POST['bill'];
$url = 'http://api.ecomexpress.in/track_me/api/mawbd/?awb='.$waybill.'&   order=&username=cs@subhashreeinfotech.com&password=@@@@';

$ch = curl_init();                    // initiate curl
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the output in     string format
$output = curl_exec ($ch);

错误:未定义的索引帐单

1 个答案:

答案 0 :(得分:0)

使用以下代码解决了问题

$waybill=$_POST['srt'];
ob_start();
echo $_POST['srt'];
$my = ob_get_contents();

$url='http://52.66.178.241//track_me/api/mawbd/?
awb='.$my.'&order=&username=subhashree54396&password=su54nbh39tmed';
$ch = curl_init();                    // initiate curl
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the output in 
string format
$output = curl_exec ($ch);
print_r($output);

curl_close($ch);