I was programming a code (which works without any inconvenience) that sends everything by HttpUrlConnection. It is the following:
protected String doInBackground(String... url){
try {
HttpURLConnection connection = (HttpURLConnection) new URL(url[0]).openConnection();
connection.setReadTimeout(10000);
connection.setConnectTimeout(15000);
//Si quiero enviar/recibir una respuesta en el cuerpo del mensaje, tiene que estar lo siguiente:
connection.setDoInput(true);
connection.setDoOutput(true);
OutputStream output=new BufferedOutputStream(connection.getOutputStream());
output.write(body.getBytes());
output.flush();
int responseCode = connection.getResponseCode();
InputStream inputStream = connection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line;
StringBuilder result = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
result.append(line);
}
String responseString = result.toString();
inputStream.close();
connection.disconnect();
return responseString;
} catch(Exception exc) {
String error = exc.toString();
return error;
}
}
The problem is that I'm making an application, which should send things by https
. However, I understand that instead of having to use HttpsUrlConnection I can keep the class I'm using ... Can that be it? Is there much difference between one and the other?