I am trying to use httpclient and I am getting media not supported error. I want to set the headers and then get the response back which should return me headers which are tokens for authentication Error: Method failed: HTTP/1.1 415 Unsupported Media Type
The procedure is as follows:
public void getDocument(String url) {
PostMethod method = new PostMethod(url);
client.getParams().setAuthenticationPreemptive(true);
method.setRequestHeader("User-Agent", "some header value");
method.addRequestHeader("Header name", "some header value");
method.addRequestHeader("Content-type", "application/xml; charset=utf-8");
method.addRequestHeader("Content-Body", "some header value");
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
Credentials defaultcreds = new UsernamePasswordCredentials("username", "password");
client.getState().setCredentials(AuthScope.ANY, defaultcreds);
try {
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
catch(Exception e) {
System.out.println("Error in getDocument() "+e);
}