2013-05-09 33 views
0

你好每一個專業,如何讓Android可以訪問HTTPS請求?

我是一個新的Android開發,最近,我剛剛進入Android的區域,現在我遇到一個問題,當我試圖使用HTTPS請求訪問服務器應用程序(像https://DEVELOPMENT_SAMPLE.com/project),我們使用Spring for Android來處理請求,並使用Apache HTTP Server + Tomcat + SSL`作爲部署環境。當我使用HTTP請求而不是HTTPS請求並從部署環境中刪除SSL時,可以成功處理訪問。我從這裏分享相關的代碼:

RestTemplate restTemplate = new RestTemplate(); 
    restTemplate.getMessageConverters().add(new GsonHttpMessageConverter()); 
    restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); 

    HttpComponentsClientHttpRequestFactory factory = new 
HttpComponentsClientHttpRequestFactory(); 
    factory.setConnectTimeout(1000 * 15); 
    restTemplate.setRequestFactory(factory); 

我知道有適用於Android兩種本地HTTP客戶端,標準的J2SE設施和HttpComponents HttpClient的。標準JS2SE工具通過SimpleClientHttpRequestFactory提供,而HttpClient通過HttpComponentsClientHttpRequestFactory提供。當您創建新的RestTemplate實例時,使用的默認ClientHttpRequestFactory會根據您的應用程序運行的Android版本而有所不同。

但我想問的問題是如何使我的HTTPS可用於Android客戶端?我想在獲取Connection對象時應該做一些改變。

非常感謝。

+0

是,安卓可以使用HTTPS通信。閱讀此鏈接:[在Android上接受HTTPS證書](http://stackoverflow.com/questions/2012497/accepting-a-certificate-for-https-on-android) – paulsm4 2013-05-09 03:07:36

+0

非常感謝您的幫助。 – 2013-05-09 03:10:07

+0

朋友,你如何將這個解決方案應用到Spring? – 2015-01-22 13:19:06

回答