将HttpPost发送到服务器;无需回应

时间:2014-07-31 15:29:33

标签: java android http-post

我想在Android上执行HttpPost来更新数据库中的单行。我不需要任何响应,验证等。所以我试图简化我的代码,因为我认为我所拥有的可能是多余的。

这就是我所拥有的:

          try {
                HttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url_select);
                httpPost.setEntity(new UrlEncodedFormEntity(param));
                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                httpEntity.getContent();

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

我需要所有这些吗?我好像可以

          try {
                HttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url_select);
                httpPost.setEntity(new UrlEncodedFormEntity(param));
                httpClient.execute(httpPost);

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

这是对的吗?

2 个答案:

答案 0 :(得分:1)

当我不饿的时候,我不会吃东西:)

是。第二部分足够好了。如果你真的不需要它,就不需要在那里得到响应对象。没关系。

答案 1 :(得分:0)

您可能还想检查简化Http连接的AQuery库:

https://code.google.com/p/android-query/

相关问题