/ /私のアンドロイドのためのSSLを使用する方法spring resttemplate - android、spring、ssl、resttemplate

私のアンドロイドのためのSSLを使用する方法spring resttemplate - android、spring、ssl、resttemplate

私はSpringのRestTemplateを使ってアクセスしています私のwebserviceが、今私はSSLを使用する必要があります。私は検索していくつかの例を見つけましたが、それは働いていませんでした(私は理解できない機能を持つ多くのtrubleを持っていました)

ここで私はこれまでこれをどのように使用しているのですか

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にするのですか?

回答:

回答№1は0

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

だから私はHttpsUrlConnectionに依存し、gsonを使ってオブジェクトを送信する

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