首页 > 解决方案 > Async HttpClient 可以将请求发布到 https 吗?

问题描述

我正在使用asyncHttpClient发布请求,它工作正常。

但是对于其中一个许可证服务器,发布请求总是在失败回调中出现。它给出了错误消息"bad Request"status 400

这个帖子请求被发送到httpsurl 不像我发出的其他请求http

asyncHttpCLient 可以发布到 https 吗?如果是,那么就 asyncHtppClient 发布请求而言,http post 和 https post 有什么区别。

我对java很陌生,所以可能缺少一些基本步骤。

我正在使用 com.loopj.android:android-async-http:1.4.9

谢谢。

标签: javaasynchronousposthttps

解决方案


简短的回答是肯定的。从图书馆网站上,它说它建立在支持安全(https)连接的apache http 组件上。

首页上的示例代码甚至使用安全 URL 显示它。

导入 com.loopj.android.http.*;

public class TwitterRestClient {
  private static final String BASE_URL = "https://api.twitter.com/1/";

  private static AsyncHttpClient client = new AsyncHttpClient();

  public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
      client.get(getAbsoluteUrl(url), params, responseHandler);
  }

  public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
      client.post(getAbsoluteUrl(url), params, responseHandler);
  }

  private static String getAbsoluteUrl(String relativeUrl) {
      return BASE_URL + relativeUrl;
  }
}

推荐阅读