2014-06-22 15 views
0

我想用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 ['username]顯示錯誤。

+0

你能告訴我們index.php的內容嗎? – Cristian

+0

<?php echo $ _POST ['username']。「」。$ _ POST ['password']; ?> –

回答

0

找到了錯誤。只好糾正網址。將其替換爲

<code> 
String link="http://10.0.2.2/monitorhealth/index.php"; 
</code>