【问题标题】:Android httpclient request and processing with entityAndroid httpclient 请求和实体处理
【发布时间】:2012-04-29 04:49:38
【问题描述】:

我向我的 servlet 发出请求

尝试 { Log.d(Constants.DEBUG_TAG_MAPS, "try"); HttpEntity 实体 = 新 StringEntity(json); post.setEntity(实体); HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 15000); HttpConnectionParams.setSoTimeout(httpParameters, 150000); httpclient = new DefaultHttpClient(httpParameters); BasicHttpResponse response = (BasicHttpResponse) httpclient.execute(post); Log.d(Constants.DEBUG_TAG_MAPS, "http 状态码:"+response.getStatusLine().getStatusCode()); if(response.getStatusLine().getStatusCode() == 200){ Log.d(Constants.DEBUG_TAG_MAPS, "响应 200"); HttpEntity responseEntity = response.getEntity(); if (responseEntity!= null) { Gson g = 新 Gson(); InputStream 是 = responseEntity.getContent(); InputStreamReader isr = new InputStreamReader(is); BufferedReader reader = new BufferedReader(isr); 尝试{ responseEntity.getContent(); 字符串 x = EntityUtils.toString(responseEntity); }catch(异常 e){ // TODO: 处理异常 } responseJSONObject = g.fromJson(reader, JSONResponseObject.class); Log.d(Constants.DEBUG_TAG_MAPS_console, responseJSONObject.toString()); reader.close(); System.gc(); } } } 捕捉(异常 e){ e.printStackTrace(); } /代码>

上线:

InputStream 是 = responseEntity.getContent();

应用程序崩溃...响应代码为 200 ... 我查看了我的 tomcat 日志,一切正常。 JSONResponseObject 填充了值并发送。

可能是什么问题?如何获取到 logcat 的堆栈跟踪?

一个可能相关的问题: 我很清楚logcat中的“无法连接工厂客户端” 任何可能导致该问题的事情都不是我的情况

  1. api 密钥正确,debug.keystore 路径更正
  2. 清单中的所有权限
  3. uses-library android:name="com.google.android.maps 也在清单中

地图显示正确,缩放/移动时刷新。

【问题讨论】:

  • stacktrace 应该在 logcat 中。可能是“System.err”作为日志标签。 + entity != null 应该检查 responseEntity
  • 它是如何崩溃的? Logcat 中必须有一些异常堆栈跟踪。请发布异常堆栈跟踪。

标签: android google-maps httpclient


【解决方案1】:

使用 google.gson.annotations 对 json 对象进行注释而不是仅实现可序列化后问题解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-31
    • 2022-01-25
    • 2015-11-18
    • 1970-01-01
    相关资源
    最近更新 更多