Android HtppGet URL connection

0

I'm trying to make an android httpget connection to php, I've done all php code connecting to mysql but start giving error starting after the "urlConnection = ..."

protected String doInBackground(String... String username = (String) arg0[0];
String password = (String) arg0[1];
String urlString = "https://splitfz.000webhostapp.com/login.php?username=" + username + "&password=" + password;
StringBuffer chaine = new StringBuffer("");

URL url;
HttpURLConnection urlConnection = null;
try {
    url = new URL("https://splitfz.000webhostapp.com/login.php?username="+ username +"&password="+ password +"");

    urlConnection = (HttpURLConnection) url.openConnection();

    connection.setRequestProperty("User-Agent", "");
    connection.setRequestMethod("GET");
    connection.setDoInput(true);
    connection.connect();

    InputStream in = urlConnection.getInputStream();

  InputStreamReader isw = new InputStreamReader(in);

    int data = isw.read();
    while (data != -1) {
        char current = (char) data;
        data = isw.read();
        System.out.print(current);
    }
    this.statusField.setText("deu certo");
} catch (Exception e) {
    this.statusField.setText("deu erro");
    e.printStackTrace();
} finally {
    if (urlConnection != null) {
        urlConnection.disconnect();
    }
}

return chaine;     }

    
asked by anonymous 19.12.2018 / 00:15

1 answer

2

I think the problem is in this snippet of code:

url = new URL("https://splitfz.000webhostapp.com/login.php?username="+ username +"&password="+ password +"");

Note that you are passing https to URL , however you are using HttpURLConnection when it should be HttpsURLConnection

For example:

url = new URL(https_url);
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();

You can read about the related methods of each of them in:

HttpURLConnection

HttpsURLConnection

If you need an example, this might help you:

Java HttpsURLConnection example

    
19.12.2018 / 11:29