I want to create an http request based on an URL in Java and change some of its headers or add new headers; then, receive the corresponding http response for that request and gets its header values and its content. How can I do this as simple as possible?
Share
Indeed use apache httpclient 4.x and use a ResponseHandler.
HttpClient has a lot of good stuff that you probably want that the raw Java API does not provide like multi threaded use, connection pooling, support for various authentication mechanisms, etc.
Below is a simple example that executes a get and returns you the body as a String.