简体   繁体   English

(Apache httpclient)3个代码有什么不同?

[英](apache httpclient) What is different thing in 3 code?

HttpClient client = new HttpClient();

//1
client.setConnectionTimeout(1000);

//2
client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 1000);

//3
client.getHttpConnectionManager().getParams().setConnectionTimeout(1000);

I want to know the main difference between this things? 我想知道这件事之间的主要区别吗?

They are all the same 他们都是一样的

There is one HttpClientParams object which is created in or provided to the constructor of HttpClient and passed to the HttpConnectionManager 有一个HttpClientParams其在创建或提供给的构造物体HttpClient并传递给HttpConnectionManager

From there, the 3 ways are just a slightly different flows to setting the same parameter in the parameters object. 从那里开始,这三种方式在参数对象中设置相同参数的流程略有不同。

For such issues have a look at the JavaDoc for the setConnectionTimeout method and the other ones. 对于此类问题,请查看JavaDoc中的setConnectionTimeout方法和其他方法。 It is likely that some of them are deprecated/bad practice depending on the version you are using. 根据您使用的版本,其中某些可能已被弃用/不当使用。 As this is OpenSource you can also read the code and see for yourself what happens behind the scenes, this is the only way to know for sure. 由于这是OpenSource,因此您还可以阅读代码并亲自了解幕后发生的事情,这是唯一可以肯定的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在使用“ apache httpclient”和“ httpurlconnection”时http状态码不同? - Why http status code is different when using “apache httpclient” and “httpurlconnection”? commache-httpclient和httpclient之间的关系是什么,都来自apache - what the relationship between commons-httpclient and httpclient, both from apache Apache HttpClient API中的CloseableHttpClient和HttpClient有什么区别? - What is the difference between CloseableHttpClient and HttpClient in Apache HttpClient API? UrlEncodedFormEntity在Apache HttpClient 4中做什么? - What does UrlEncodedFormEntity do in Apache HttpClient 4? 将cURL转换为Apache httpclient JAVA代码 - Converting cURL into apache httpclient JAVA code Apache HttpClient 3,对于每个请求具有不同凭据的多线程? - Apache HttpClient 3, multi threaded with different credential for each request? 根据HttpGet通过Apache的HttpClient返回的内容发布到表单 - Posting to a form based on what HttpGet returns with Apache's HttpClient 如何将此 curl 请求转换为 Apache HttpClient java 代码? - How do I convert this curl request to Apache HttpClient java code? 出于什么原因从Apache httpClient中删除了预身份验证? - For what reason was pre-authentication removed from Apache httpClient? 要使用apache httpclient,必须在远程http服务器上安装什么 - What has to be installed on the remote http server to use apache httpclient
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM