2014-10-08 73 views
0

我有android應用程序,在android應用程序中我執行了mysql數據庫表的select查詢。如何從輸入流獲取字符串值?

HttpClient httpclient = new DefaultHttpClient(); 
      HttpPost httppost = new HttpPost("http://www.mywebsite.com/select.php"); 
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8)); 
      HttpResponse response = httpclient.execute(httppost); 
      HttpEntity entity = response.getEntity(); 
      InputStream is = entity.getContent(); 
      //if(compare is value here) 

這裏我想檢查InputStream is的價值。

,當我在瀏覽器中執行http://www.mywebsite.com/select.php我得到這樣{name : ashu}null

產值,但我怎麼能比較這是我的代碼,因爲我無法檢查is==null :(

+1

5種方法將InputStream轉換爲Java中的字符串http://javarevisited.blogspot.com/2012/08/convert-inputstream-to-string-java-example-tutorial.html – mmcrae 2014-10-08 14:56:47

+0

並且可能您需要一個HttpGet – Blackbelt 2014-10-08 14:57:07

回答

0

您需要在您的<uses-permission android:name="android.permission.INTERNET"/>清單文件

+0

我很好e已經使用了相同的 – Neo 2014-10-08 15:11:43

+0

看看這個mybe它可以幫助你http://stackoverflow.com/questions/16097824/null-pointer-exception-http-entity – Jamal 2014-10-08 15:20:11