Tried searching our blog but was not able to find some pointers so posting,
I was just working on a httpsClient Post method code as below and facing IOException
. little Pointers may help , dont require detailed answers.
HttpClient httpclient = new HttpClient();
request = new PostMethod("https://ref.net/auth/token?grant_type=password");
request.setRequestHeader("Authorization", "Basic KolokYrZTo=");
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
NameValuePair[] data = {
new NameValuePair("username", "abc"),
new NameValuePair("password", "123"),
new NameValuePair("grant_type", "password"),
};
request.setRequestBody(data);
httpclient.executeMethod(request);
} catch (IOException e) {
e.printStackTrace();
logger.error( "IOException in post()...."+e.getMessage());
}
I am running this code on eclipse with commons-httpClient 3.1.jar it runs perfectly fine, But when i move my code to server and try to run the same code, the httpclient.executeMethod(request);
throws IOException. To my surprise the e.printStackTrace();
does not prints as e
object itself is null
How do i catch this exception and debug this, I am doing something wrong here.
On my local i have Java1.8 but running at compiler compliance level 1.6- On server. I tried running both 1.8 and 1.6 same error.