0

I am trying to read the HTML code from a URL into a string as part of an Android app. It all works perfectly when I use "https://www.google.com", but when I use the website I want to get data from, "https://bmorgan17.github.io/DCD/resources/data_raw.html" I get this error.

Error: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x5c959090: Failure in SSL library, usually a protocol error
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x59282c38:0x00000000)

Here is my code:

public class RecipeActivity extends AppCompatActivity {
static String result;

static private class RetrieveData extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... urlStr){
        // do stuff on non-UI thread
        StringBuilder htmlCode = new StringBuilder();
        String LOG_TAG = "APP";
        try{
            URL url = new URL(urlStr[0]);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

            String inputLine;

            while ((inputLine = in.readLine()) != null) {
                htmlCode.append(inputLine);
            }

            in.close();
        } catch (Exception e) {
            e.printStackTrace();
            Log.wtf(LOG_TAG, "Error: " + e.getMessage());
            Log.wtf(LOG_TAG, "HTML CODE: " + htmlCode);
        }
        Log.wtf(LOG_TAG, "HTML CODE: " + htmlCode);
        return htmlCode.toString();
    }

    @Override
    protected void onPostExecute(String htmlCode){
        // do stuff on UI thread with the html
        super.onPostExecute(htmlCode);
        result = htmlCode;
    }
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setContentView(R.layout.activity_recipe);
    TextView out = findViewById(R.id.tvHttp);

    new RetrieveData().execute("https://bmorgan17.github.io/DCD/resources/data_raw.html");
    out.setText(result);
}

}

If anyone could help me it would be great!

Edit:

  • Galaxy Nexus
  • Android Version: 4.2.2
  • Min API: 17

I use this as a test phone because it is much faster than the emulator. If I need to make an emulator for a newer phone please tell me.

PR06GR4MM3R
  • 397
  • 2
  • 13
  • You should add information about your android system. There is a known problem with SSL handshake in Android 7 (https://stackoverflow.com/questions/39133437/sslhandshakeexception-handshake-failed-on-android-n-7-0) – Jens Dibbern Jan 26 '19 at 17:20
  • @JensDibbern done – PR06GR4MM3R Jan 26 '19 at 17:25
  • 1
    That is simple: Your Android version does not support TLS 1.2 and your server enforces TLS 1.2. Maybe this will help: https://medium.com/tech-quizlet/working-with-tls-1-2-on-android-4-4-and-lower-f4f5205629a But basically this version is too old to be used for safe internet communication. For TLS 1.2 (older versions are considered unsafe) you will need at least Android 4.4.2 afaik. – Jens Dibbern Jan 26 '19 at 17:32

0 Answers0