2016-09-02 3 views
1

私はwebサービスにアクセスするためにSpringのRestTemplateを使用していましたが、今ではSSLを使用する必要があります。アイブ氏はいくつかの例が、働いどれを検索し、発見されて私のandroid spring resttemplateにSSLを使用する方法

ここ

iはGradleの

これまで

RestTemplate restTemplate = new RestTemplate(); 
// Add the String message converter 
restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); 
// Make the HTTP GET request, marshaling the response to a String 
String result = restTemplate.getForObject(urlQuery, String.class, "GetUnit/" + tM.getDeviceId()); 
} 

それを使用する方法です(私は私が把握カント廃止予定の機能と困りの多くを持っていました)

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.2.1' 
    compile 'com.android.support:support-v4:23.2.1' 
    compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3' 
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.1' 
} 

これをsslにするにはどうすればよいですか?

答えて

0

私は春を捨てました。私は春を使って解決策を見つけることができませんでした。

だから今は、HttpsURLConnectionのに依存しており、オブジェクト

public String GetUnit(String url) { 
     String result = null; 
     HttpURLConnection urlConnection = null; 
     try { 
      URL requestedUrl = new URL(url); 
      urlConnection = (HttpURLConnection) requestedUrl.openConnection(); 
      if (urlConnection instanceof HttpsURLConnection) { 
       ((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslContext.getSocketFactory()); 
       ((HttpsURLConnection) urlConnection).setHostnameVerifier(new BrowserCompatHostnameVerifier()); 
      } 
      urlConnection.setRequestMethod("GET"); 
      urlConnection.setConnectTimeout(1500); 
      urlConnection.setReadTimeout(1500); 
      lastResponseCode = urlConnection.getResponseCode(); 
      result = IOUtil.readFully(urlConnection.getInputStream()); 
     } catch (Exception ex) { 
      result = ex.toString(); 
     } finally { 
      if (urlConnection != null) { 
       urlConnection.disconnect(); 
      } 
     } 
     return result; 
    } 
を送信するためgsonを使用して
関連する問題