使用SSL类

时间:2015-09-14 07:41:43

标签: android ssl

知道我缺少什么吗?

使用SSL类的HttpClient Web服务出错。与SSL客户端连接时的HTTPClient连接问题--- 增加的进口是: -

 import android.app.Activity;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import com.gns.socialtongits.net.ssl.SSLClient;
 import com.gns.socialtongits.util.Log;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.message.BasicNameValuePair;
 import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import java.io.IOException;
 import java.net.URLEncoder;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;


 // And Class Methods are:-
public class SSLClient extends DefaultHttpClient {

    public SSLClient(HttpParams hparms) {
        super(hparms);
    }

    @Override
    protected ClientConnectionManager createClientConnectionManager() {
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory
                .getSocketFactory(), 80));

        // Register for port 443 our SSLSocketFactory with our keystore
        // to the ConnectionManager
        registry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

        // http://blog.synyx.de/2010/06/android-and-self-signed-ssl-certificates/
        return new SingleClientConnManager(getParams(), registry);
    }
}

运行项目后收到的错误消息 -

Process: com.gns.socialtongits.pro.android, PID: 8487
java.lang.NoClassDefFoundError: com.gns.socialtongits.net.ssl.SSLClient
at com.gns.socialtongits.net.HttpUtil.get(HttpUtil.java:162)
at com.gns.socialtongits.net.WebServiceHelperImpl.getConfiguration(WebServiceHelperImpl.java:36)
at com.gns.socialtongits.android.SocialTongitsApps$2.run(SocialTongitsApps.java:310)
at java.lang.Thread.run(Thread.java:841)

0 个答案:

没有答案