問題描述:
android 需要支持https界面或者對應的接口調用,不希望接口參數明文傳輸。
實現方案:
android HttpClient 提供添加ssl支持,其需要添加以下代碼:
SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager( httpParams, schemeRegistry); httpClient = new DefaultHttpClient(conMgr,httpParams); |
當然server端也必須安裝相應的證書,否則會報證書錯誤不能加載。