我正在使用HttpPost从我的服务器请求代码,但它工作正常,直到我添加其他参数。这是我的代码:
private String getShareCode(String t, String d, String lat, String lng) {
String respTxt;
try{
HttpClient dbClient = new DefaultHttpClient();
HttpPost actionPost = new HttpPost(Config.URL_CODE);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("t",t));
params.add(new BasicNameValuePair("d",d));
params.add(new BasicNameValuePair("lat",lat));
params.add(new BasicNameValuePair("lng",lng));
actionPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse dbResp = dbClient.execute(actionPost);
HttpEntity ent = dbResp.getEntity();
respTxt = EntityUtils.toString(ent).trim();
Log.i("ShareCode", t + ", " + d + ", " + lat + ", " + lng);
Log.i("ShareCode",respTxt);
}catch(Exception e){
e.printStackTrace();
Log.i("ShareCode", String.valueOf(e));
respTxt = null;
}
return respTxt;
}
我的PHP代码是:
<? //Receive post data
echo $t = $_POST['t'];
$d = $_POST['d'];
$l = $_POST['lat'];
$lo= $_POST['lng'];
现在,我不知道发生了什么事,因为我总是得到这样的回应:
Notice: Undefined index: t in /home/iplaces/public_html/iplaces_url.php on line 17
Notice: Undefined index: d in /home/iplaces/public_html/iplaces_url.php on line 18
Notice: Undefined index: lat in /home/iplaces/public_html/iplaces_url.php on line 19
Notice: Undefined index: lng in /home/iplaces/public_html/iplaces_url.php on line 20
我希望你能帮助我,我对此有点紧张......
答案 0 :(得分:0)
试试这个:
它会将数据发送到请求对象。
<? //Receive post data
echo $t = $_REQUEST['t'];
$d = $_REQUEST['d'];
$l = $_REQUEST['lat'];
$lo= $_REQUEST['lng'];