Problems when reusing a org.apache.commons.httpclient.methods.PostMethod object
I've noticed that if I reuse a PostMethod object by calling setRequestEntity(...), there are errors on the server side because the request is not parsed correctly. It seems as though the length of the body of the request is set the first time I call setRequestEntity, and this length is not being reset after the second time I call setRequestEntity.
Everything works fine if I use a separate P开发者_开发问答ostMethod object for each request, but is there a way to reuse a PostMethod object for different requests since calling setRequestEntity(...) alone is not sufficient to update the content of the request?
No. You can reuse HttpClient instances but not Method instances. They are normally one time use.
Don't worry about reusing PostMethod objects, just create new ones. The JVM nowadays quickly identifies such short lived objects and collects them.
精彩评论