org.apache.commons.httpclient.HttpMethod of Commons HttpClient 3.0.1替换httpcomponents HttpClient 4.5.1?

时间:2016-03-01 12:47:26

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

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

“httpcomponents HttpClient 4.5.1”中是否有可用于HttpMethod的替代品?如果没有有没有其他方法来使用“httpcomponents HttpClient 4.5.1”获取“getResponseHeader()”?

1 个答案:

答案 0 :(得分:0)

如果您正在寻找所有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);

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