我是 Android 编程新手,但对 PHP 有相当的了解。
我正在尝试通过发布请求将数据发送到我的服务器。我有以下代码:
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("year","1980"));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream inps = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inps));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
inps.close();
result=sb.toString();
Log.v("data-received",result);
我在互联网上的许多地方都找到了代码。
在 PHP 方面,我正在写这个:
<?php
echo "something".$_REQUEST['year'];
?>
但是我只得到“某物”(在日志值“数据接收”中)作为我的应用程序端的输出?
我究竟做错了什么?我需要设置任何环境变量等吗?