0
private String SendAndReceived() {

        HttpURLConnection con = Connector.connect(urlAddress);
        if (con == null) {

            return null;
        }

        try {

            OutputStream os = con.getOutputStream();

            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
            bw.write(new DataPackager(query).packData());

            bw.flush();

            bw.close();
            os.close();

            int responseCode = con.getResponseCode();
            StringBuffer response = new StringBuffer();

            if (responseCode == con.HTTP_OK) {

                InputStream is = con.getInputStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(is));

                String line;

                if (br != null) {

                    while ((line = br.readLine()) != null) {

                        response.append(line + "\n");
                    }

                } else {
                    return null;
                }

                br.close();
                is.close();

                return response.toString();


            } else {
                return String.valueOf(responseCode);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

}

debug:

W/System.err: java.io.IOException: Cleartext HTTP traffic to www.yesia.com not permitted
W/System.err:     at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:115)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:458)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:258)
W/System.err:     at com.yesia.searchrecyclerview.MySQL.SenderReceiver.SendAndReceived(SenderReceiver.java:93)
W/System.err:     at com.yesia.searchrecyclerview.MySQL.SenderReceiver.doInBackground(SenderReceiver.java:51)
W/System.err:     at com.yesia.searchrecyclerview.MySQL.SenderReceiver.doInBackground(SenderReceiver.java:19)
Kris
  • 8,680
  • 4
  • 39
  • 67
yesia Plorina
  • 103
  • 1
  • 7

1 Answers1

0

You have to add an attribute of android:usesCleartextTraffic="true" on application tag in AndroidManifes.xml file.

And also add this.

<uses-library
    android:name="org.apache.http.legacy"
    android:required="false" />

Check this official blog on why this happens and we have to add in the manifest file.

Kaushal Panchal
  • 1,785
  • 1
  • 11
  • 27