2016-09-02 4 views
1

저는 웹 서비스에 액세스하기 위해 Spring의 RestTemplate를 사용해 왔지만 이제는 SSL을 사용해야합니다. 필자는 몇 가지 예이지만 근무 없음을 검색하고 발견 된내 안드로이드 스프링 resttemplate에 SSL을 사용하는 방법

다음

내가 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()); 
} 

를 사용하는 방법이다 (I 내가 알아낼 어차피 사용되지 않는 기능 truble 많이했다)

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' 
} 

어떻게해야합니까?

답변

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를 사용하여
관련 문제