首页 文章

Android httpclient请求和处理实体

提问于
浏览
0

我向我的servlet发出请求

try {
                Log.d(Constants.DEBUG_TAG_MAPS, "try");

                HttpEntity entity = new StringEntity(json);
                post.setEntity(entity);

                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 status code : "+response.getStatusLine().getStatusCode());
                if(response.getStatusLine().getStatusCode() == 200){
                    Log.d(Constants.DEBUG_TAG_MAPS, "response 200");
                    HttpEntity responseEntity = response.getEntity();
                    if (responseEntity!= null) {
                        Gson g = new Gson();

                        InputStream is = responseEntity.getContent();
                        InputStreamReader isr = new InputStreamReader(is);
                        BufferedReader reader = new BufferedReader(isr);

                        try{
                            responseEntity.getContent();
                            String x = EntityUtils.toString(responseEntity);
                        }catch (Exception e) {
                            // TODO: handle exception
                        }

                        responseJSONObject = g.fromJson(reader, JSONResponseObject.class);
                        Log.d(Constants.DEBUG_TAG_MAPS_console, responseJSONObject.toString());
                        reader.close();
                        System.gc();    
                    }

                }   


            } catch (Exception e) {
                e.printStackTrace();
            }

/code>

并在线:

InputStream是= responseEntity.getContent();

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

可能是什么问题呢?如何将堆栈跟踪转换为logcat?

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

  • api key是正确的,修正debug.keystore的路径

  • 清单中的所有权限

  • uses-library android:name =“com.google.android.maps in manifest

Map 显示正确,在缩放/移动时刷新 .

1 回答

  • 0

    使用google.gson.annotations anotate json对象后解决问题,而不仅仅是实现serializable .

相关问题