Hello to all. People, tell me, please, Java library for sending / receiving requests via HTTP. Interested in an analogue of the type of the https://code.google.com/p/phpsvnclient/source/browse/branches/khartn/http.php class which can send requests in the form

Args: Array ( [Protocol] => http [HostName] => ihtika.googlecode.com [Headers] => Array ( [Host] => ihtika.googlecode.com [User-Agent] => phpsvnclient (http://phpsvnclient.googlecode.com/) [Authorization] => Basic Og== [Content-Type] => text/xml [Depth] => 1 [Content-Length] => 202 ) [HostPort] => 0 [RequestURI] => /svn/!svn/bc/158/trunk/src/com/google/code/ihtika/IhtikaClient/MainThread.java/ [RequestMethod] => REPORT [Body] => <?xml version="1.0" encoding="utf-8"?> <S:log-report xmlns:S="svn:"> <S:start-revision>0</S:start-revision><S:end-revision>100</S:end-revision><S:path></S:path><S:discover-changed-paths/></S:log-report> ) 

That is, with the ability to form headers, specify RequestMethod and add Request Body. I looked in the direction of http://hc.apache.org/httpclient-3.x/ , but did not see such an opportunity there ...

    1 answer 1

    All this, of course, is possible in HttpClient, otherwise it would not be so popular.

    Here is an example of working with POST:

     PostMethod post = new PostMethod("http://jakarata.apache.org/"); NameValuePair[] data = { new NameValuePair("user", "joe"), new NameValuePair("password", "bloggs") }; post.setRequestBody(data); // execute method and handle any error responses. ... InputStream in = post.getResponseBodyAsStream(); // handle response. 

    As you can see, we set both the method and the request body. About the application of various methods are written here .

    To set headers, use the appropriate method HttpMethod.addRequestHeader

    Shl. JavaDoc is our everything. http://hc.apache.org/httpclient-3.x/apidocs/overview-summary.html

    ZYY. In addition there are official examples here .


    For newly discovered circumstances, I change the answer. Apparently you need something like the Apache Jackrabbit WebDAV Library .

    • Will these examples work with httpclient-4.1.1? Something I do not see in httpclient-4.1.1.jar class org.apache.commons.httpclient.methods.GetMethod After all, I need GET, not POST. And, what about when a GET request executes a GET request, and in my case you need to execute a REPORT request ... How do I replace the GET with [RequestMethod] => REPORT? - Arthur
    • So you need a GET request that has a body too? And if not difficult, tell me what kind of REPORT request. I do not remember this in the HTTP standard. UPD. Everything, I understand what you want. To support REPORT, you need a non-HTTP client implementation, but WebDAV. Look this way. - Nofate
    • And which JAVA WebDAV clients support sending requests? For example, sardine provides only a standard set of functions like move copy, etc. What kind of client can I send the request I need? - Arthur
    • The issue is decided. Thank you Nofate for the tip. Decided using httpclient-4.1.1. I had to analyze another software product to solve the problem ... - Arthur