Hope this helps. This is the code that I used and worked perfectly.
private HttpClient createHttpClient() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(params, true); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg); return new DefaultHttpClient(conMgr, params); }
Then create an HttpClient as follows: -
HttpClient httpClient = createHttpClient();
and use it with HttpPost.
Hooray!!
EDIT
And I did not use RestTemplate in my code. I made a simple request. If you need more help, just let me know. It seems that I recently did something similar to what you are looking for.
Varundroid
source share