2014-10-08 53 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

相关问题