【问题标题】:org.apache.commons.httpclient.HttpMethod of Commons HttpClient 3.0.1 replacement in httpcomponents HttpClient 4.5.1?org.apache.commons.httpclient.HttpMethod 的 Commons HttpClient 3.0.1 替换 httpcomponents HttpClient 4.5.1?
【发布时间】:2016-11-15 13:20:14
【问题描述】:

我们正在从 Commons HttpClient 3.0.1 迁移到 httpcomponents HttpClient 4.5.1。 目前我们面临一个与迁移版本(httpcomponents HttpClient 4.5.1)中不存在的 HttpMethod 类相关的问题。我们正在从 HttpMthod 类执行“getResponseHeader()”操作。

“httpcomponents HttpClient 4.5.1”中的 HttpMethod 有替代品吗?如果不是还有其他方法可以使用“httpcomponents HttpClient 4.5.1”获取“getResponseHeader()”吗?

【问题讨论】:

  • 即使我也有同样的疑问。我最终使用了单独的方法,即一种用于 Get ,一种用于 Post 。最好分别使用这两种方法,因为 HttpUriRequest 不能满足与方法相关的所有要求跨度>

标签: apache-httpclient-4.x apache-commons-httpclient


【解决方案1】:

如果您正在寻找所有 http 方法的通用接口,请使用 HttpUriRequest:

String url = "http://www.example.com";
HttpUriRequest get = new HttpGet(url);
HttpUriRequest post = new HttpPost(url);

...
HttpClient client = HttpClientBuilder.create.build();
HttpResponse response = client.execute(get or post);

所有与响应相关的属性(标头、返回码和输出流)都可以通过响应对象访问,这更明智!

【讨论】:

    猜你喜欢
    • 2011-08-26
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多