Apache HTTPClient POST request sample code

This extends the Apache HTTPClient Tutorial to invoke RESTFul service with a POST request.

The pom.xml

The client using HttpClient & JAXBContext

The “JAXBContext” is from the Java 6 onwards. The sample code includes

1) Exception handling.

2) “BasicCredentialsProvider” is used for the basic authentication.

3) “JAXBContext” is used for marshalling & unmarshalling.

4) HTTP headers.

Marshalling Logic
Unmarshalling Logic

Java Interview FAQs

800+ Java Interview Q&As