I am creating HTTP request using Apache HTTP Client version 4.3.4. I see there are some classes like HttpGet,... and there is also a class BasicHttpRequest. I am not sure which one to use. Whats the difference and which one should be used in which condition ?
我正在使用Apache HTTP Client版本4.3.4创建HTTP请求。我看到有一些类像HttpGet,...还有一个类BasicHttpRequest。我不确定使用哪一个。差异是什么,应该在哪种条件下使用?
2 个解决方案
#1
BasicHttpRequest
is provided by the core library. As its name suggests it is pretty basic: it enforces no particular method name or type, nor does it attempt to validate the request URI. The URI parameter can be any arbitrary garbage. HttpClient will dutifully transmit it to server as is, if it is unable to parse it to a valid URI.
BasicHttpRequest由核心库提供。顾名思义它非常基本:它不强制执行任何特定的方法名称或类型,也不会尝试验证请求URI。 URI参数可以是任意垃圾。如果HttpClient无法将其解析为有效的URI,它将尽职尽责地将其传输到服务器。
HttpUriRequest
variety on the other hand will enforce specific method type and will require a valid URI. Another important feature is that HttpUriRequest can be aborted at any point of their execution.
另一方面,HttpUriRequest变种将强制执行特定的方法类型,并且需要有效的URI。另一个重要特性是HttpUriRequest可以在执行的任何时候中止。
You should always be using classes that implement HttpUriRequest
per default.
您应该始终使用默认情况下实现HttpUriRequest的类。
#2
I was just browsing the 4.3.6 javadoc attempting to locate your BasicHttpRequest and was unable to find it. Do you have a reference to the javadoc of this class?
我只是浏览4.3.6 javadoc试图找到你的BasicHttpRequest并且无法找到它。你有这个类的javadoc的引用吗?
I would be under the impression that BasicHttpRequest would be a base class providing operations and attributes common to more than one HttpRequest. It may be extremely generic for extension purposes.
我认为BasicHttpRequest将是一个基类,提供多个HttpRequest共有的操作和属性。对于扩展目的,它可能非常通用。
To the first part of your question, use HttpGet, HttpPost etc for their specific operations. If you only need to HTTP/GET information then use HttpGet, if you need to post a form or document body, then use HttpPost. If you are attempting to use things like the Head, Put, Delete method, then use the correspoding HttpXXX class.
对于问题的第一部分,请使用HttpGet,HttpPost等进行特定操作。如果您只需要HTTP / GET信息,那么使用HttpGet,如果您需要发布表单或文档正文,则使用HttpPost。如果您尝试使用Head,Put,Delete方法,请使用对应的HttpXXX类。
#1
BasicHttpRequest
is provided by the core library. As its name suggests it is pretty basic: it enforces no particular method name or type, nor does it attempt to validate the request URI. The URI parameter can be any arbitrary garbage. HttpClient will dutifully transmit it to server as is, if it is unable to parse it to a valid URI.
BasicHttpRequest由核心库提供。顾名思义它非常基本:它不强制执行任何特定的方法名称或类型,也不会尝试验证请求URI。 URI参数可以是任意垃圾。如果HttpClient无法将其解析为有效的URI,它将尽职尽责地将其传输到服务器。
HttpUriRequest
variety on the other hand will enforce specific method type and will require a valid URI. Another important feature is that HttpUriRequest can be aborted at any point of their execution.
另一方面,HttpUriRequest变种将强制执行特定的方法类型,并且需要有效的URI。另一个重要特性是HttpUriRequest可以在执行的任何时候中止。
You should always be using classes that implement HttpUriRequest
per default.
您应该始终使用默认情况下实现HttpUriRequest的类。
#2
I was just browsing the 4.3.6 javadoc attempting to locate your BasicHttpRequest and was unable to find it. Do you have a reference to the javadoc of this class?
我只是浏览4.3.6 javadoc试图找到你的BasicHttpRequest并且无法找到它。你有这个类的javadoc的引用吗?
I would be under the impression that BasicHttpRequest would be a base class providing operations and attributes common to more than one HttpRequest. It may be extremely generic for extension purposes.
我认为BasicHttpRequest将是一个基类,提供多个HttpRequest共有的操作和属性。对于扩展目的,它可能非常通用。
To the first part of your question, use HttpGet, HttpPost etc for their specific operations. If you only need to HTTP/GET information then use HttpGet, if you need to post a form or document body, then use HttpPost. If you are attempting to use things like the Head, Put, Delete method, then use the correspoding HttpXXX class.
对于问题的第一部分,请使用HttpGet,HttpPost等进行特定操作。如果您只需要HTTP / GET信息,那么使用HttpGet,如果您需要发布表单或文档正文,则使用HttpPost。如果您尝试使用Head,Put,Delete方法,请使用对应的HttpXXX类。