为什么不是服务器返回什么? [英] Why isn't the server returning anything?
本文介绍了为什么不是服务器返回什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面这段code的检索基本上是从一个PHP页面(www.ace.ucv.ro/android/android.php)。
I used the following piece of code to retrieve basically a JSON formatted String from a php page (www.ace.ucv.ro/android/android.php).
由于某种原因,不管我怎么努力,字符串结果仍然是空的,没有什么是储存在里面,甚至当我使用一个特殊的功能,它的InputStream转换成字符串(使用BufferedReader类)。
For some reason, no matter what I try, the string "result" remains empty, nothing is stored inside it, even when I use a special function to convert it from InputStream to String (with BufferedReader).
在这我想存储字符串被称为结果。
The String in which I want to store is called "RESULT".
public void connect(String url){
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response;
try{
response = client.execute(httpGet);
Log.i("Praeda", response.getStatusLine().toString());
HttpEntity entity = response.getEntity();
if(entity != null){
result = entity.getContent().toString();
}
if(entity == null){
result = "failed";
}
}catch(Exception e){
e.printStackTrace();
}
}
你可能有任何建议将是巨大的......
Any suggestions you might have would be great...
推荐答案
JSON响应通常gzip压缩,试试这个
JSON response is normally gzipped, try this
jsonResponse = client.execute(httpGet);
InputStream in = response.getEntity().getContent();
GZIPInputStream gin = new GZIPInputStream(in);
BufferedReader reader = new BufferedReader(new InputStreamReader(gin));
String line;
while ((line = reader.readLine()) != null) {
jsonResponse.append(line);
}
reader.close();
这篇关于为什么不是服务器返回什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文