Reputation: 832
I'm a noob with Android development, so bear with me. I'm trying to figure out how to make a secure HTTPS POST in Android for a REST API call, and I tried the following method (provided at Secure HTTP Post in Android)
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);
}
However, I pasted this into my code, and I think I imported everything that's necessary, but Eclipse is complaining about this line:
schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
It says "The method getSocketFactory() is undefined for the type SSLSocketFactory". Has this been deprecated, and is there a newer way to do this?
Any help would be much appreciated. Thanks.
Upvotes: 0
Views: 801
Reputation: 832
I figured out what my issue was. I was importing javax.net.ssl.SSLSocketFactory instead of org.apache.http.conn.ssl.SSLSocketFactory. Eclipse automatically added the wrong import statement.
Thanks to the comment located at http://thinkandroid.wordpress.com/2009/12/31/creating-an-http-client-example/#comment-77
Upvotes: 1