Lothar Kimmeringer wrote:
The last time I checked, GetMethod and PostMethod were two
classes sharing a lot of methods but not a common superclass.
So you end up with code like this
if (performGet) {
methodGet = new GetMethod(host + url);
methodGet.setQueryString(query);
methodGet.setDoAuthentication(authNeeded);
methodGet.getParams().setParameter("http.socket.timeout",
Integer.valueOf(timeout));
methodGet.getParams().setParameter(
HttpMethodParams.RETRY_HANDLER, retryhandler);
methodGet.setRequestHeader("Connection", "keep-alive");
methodGet.setRequestHeader("Cache-Control", "no-cache");
}
else {
methodPost = new PostMethod(host + url);
methodPost.setRequestHeader("Connection", "keep-alive");
methodPost.setDoAuthentication(authNeeded);
methodPost.getParams().setParameter("http.socket.timeout",
Integer.valueOf(timeout));
methodPost.getParams().setParameter(
HttpMethodParams.RETRY_HANDLER, retryhandler);
methodPost.setRequestHeader("Cache-Control", "no-cache");
}
if (methodGet != null){
statuscode = client.executeMethod(methodGet);
}
else{
statuscode = client.executeMethod(methodPost);
}
and so on. If you have a specific HTTP-session to handle
programmatically, HttpClient is nice, but if you have to
build different HTTP-requests in dependence of external
configurations, you have a lot of duplicate code that
is prone to errors.
Daniel Pitts wrote:
Last time I checked, they both implement HttpMethod and are derived from
HttpMethodBase. Perhaps you had a really old version, or misinterpreted
something else.
I'm not seeing either one, nor 'HttpMethodBase', nor 'HttpMethod' in
the HttpClient Javadocs. I find 'HttpGet' and 'HttpPost', which
inherit from 'HttpRequestBase' and implement 'HttpMessage', and seem
roughly equivalent to what you're talking about.
<http://hc.apache.org/httpcomponents-client/httpclient/apidocs/
index.html>
From <http://hc.apache.org/>:
"HttpComponents Client is a successor of and replacement for Commons
HttpClient 3.x. Users of Commons HttpClient are strongly encouraged to
upgrade. ...
"Commons HttpClient 3.x codeline is nearing the end of life. All users
of Commons HttpClient 3.x are strongly encouraged to upgrade to
HttpClient 4.0."
--
Lew
discrepancy.