Thursday, 15 August 2013

The constructor Scheme(String, SSLSocketFactory, int) is undefined

The constructor Scheme(String, SSLSocketFactory, int) is undefined

I'm attempting to perform an HttpPost through a secure connection. Many
guides online suggest to use SchemeRegistry to modify the HttpClient. I
have a SSL context object (tailored to my certificate) globally assigned
and the getSocketFactory() method returns an SSLSocketFactory (not
SocketFactory). The API for Scheme shows no constructor for
SSLSocketFactory but the guides show a contructor using the
SSLSocketFactory object. Casting it to a SocketFactory object does not
work. I've tried countless work arounds, including different imports, and
nothing is working.
Here is my code: (error on line 6)
HttpContext localContext = new BasicHttpContext();
HttpClient httpclient = new DefaultHttpClient();
ClientConnectionManager ccm = httpclient.getConnectionManager();
SchemeRegistry schemeRegistry = ccm.getSchemeRegistry();
schemeRegistry.register(new Scheme("http",
PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https",
Variables.context.getSocketFactory(), 443));
HttpParams params = new BasicHttpParams();
HttpPost httppost = new HttpPost(url);
try {
File file = new File(filepath);
FileEntity entity;
entity = new FileEntity(file, "image/jpeg");
entity.setChunked(true);
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost, localContext);
}

No comments:

Post a Comment