это мой вопрос / проблема:
Я делаю URL-запрос к серверу, который аутентифицируется по SSL через https, но при получении ответа всегда возвращается пустым, когда я преобразовываю ввод в строку.
Другой вызов без параметров всегда проходит гладко
Есть идеи?
URL: https://www.server.com/api/getResources.php?res[]=Argentina&res[]=Australia&res[]=Bolivia
И код:
HttpURLConnection http = conectar(URL);
InputStream urlInputStream = null;
try {
urlInputStream = http.getInputStream();
} catch (IOException e) {
}
метод конектара:
private HttpURLConnection conectar(String surl) {
URL url = null;
try {
url = new URL(surl);
} catch (MalformedURLException e) {
}
HttpURLConnection http = null;
if (url.getProtocol().toLowerCase().equals("https")) {
trustEveryone();
HttpsURLConnection https = null;
try {
https = (HttpsURLConnection) url.openConnection();
} catch (IOException e) {
}
// https.setHostnameVerifier(DO_NOT_VERIFY);
http = https;
} else {
try {
http = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
}
}
Authenticator.setDefault(new MyAuthenticator());
return http;
}
Метод trustEveryone:
HttpsURLConnection
.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname,
SSLSession session) {
return true;
}
});
SSLContext context = SSLContext.getInstance("TLS"); // TLS
context.init(null, new X509TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context
.getSocketFactory());