【问题标题】:Sending HttpPost to Server; No Response needed将 HttpPost 发送到服务器;无需回应
【发布时间】:2014-07-31 15:29:33
【问题描述】:

我想在 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();
            }

这是正确的吗?

【问题讨论】:

  • 没有理由不工作

标签: java android http-post


【解决方案1】:

我不饿的时候不吃东西:)

是的。第二部分已经足够好了。如果您真的不需要它,则无需在那里获取响应对象。没关系。

【讨论】:

  • 谢谢,我养成了剪切和粘贴大量 http 调用的坏习惯,然后开始查看我实际在做什么,这似乎是多余的。将标记为正确。
  • @KickingLettuce 当然。发生。没问题。很高兴能提供帮助。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 2014-08-19
    • 2013-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多