我正在尝试使用android和php登录系统。我可以从url读取响应,但是$ _POST数组总是空的。我是新的,所以任何帮助都会受到赞赏。这是我的android代码。
protected String doInBackground(String... params) {
try {
String link="http://10.0.2.2/monitorhealth";
HttpClient httpClinet=new DefaultHttpClient();
HttpPost httppost=new HttpPost(link);
List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username","X"));
nameValuePairs.add(new BasicNameValuePair("password","Y"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpClinet.execute(httppost);
InputStream inputStream=response.getEntity().getContent();
InputStreamReader inputStreamReader=new InputStreamReader(inputStream);
BufferedReader bufferedReader=new BufferedReader(inputStreamReader);
StringBuilder sb=new StringBuilder();
String line;
while((line=bufferedReader.readLine())!=null){
sb.append(line);
}
Log.e("Response","Received:"+sb.toString());
return sb.toString();
}
在index.php中只有一个语句$ _POST [&#39; username]显示错误。
答案 0 :(得分:0)
发现错误。只需更正网址。用
替换它<code>
String link="http://10.0.2.2/monitorhealth/index.php";
</code>