0

I have an event on a Button which makes a HttpURLConnection in order to access an API Service which is on my local server to retrieve a JSON. When I click the Button it gives me :

"D/NetworkSecurityConfig: No Network Security Config specified, using platform default"

But then when I press again the Button it gives me the JSON string. So my question is : how do I make it to give me the JSON the first time I press the Button without pressing it 2 times.

This is the code

        URL url = new URL(params[0]);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
        connection.setDoInput(true);

        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        json = reader.readLine();

        return json;
Mihai
  • 101
  • 2
  • 2
  • 8
  • show me your code – Jd Prajapati Feb 24 '17 at 13:25
  • That debugging message does not indicate any sort of problem. I recommend that you ask a separate Stack Overflow question, where you provide a [mcve], and focus less on that message and more on the specific results from your code. `HttpURLConnection` is synchronous, and so you know exactly what you are getting back from your first request -- what is it? – CommonsWare Feb 24 '17 at 13:29
  • URL url = new URL(params[0]); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); connection.setDoInput(true); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); json = reader.readLine(); return json; – Mihai Feb 24 '17 at 14:06
  • I edited my post by adding the code. Maybe this is producing that message. – Mihai Feb 24 '17 at 14:09

0 Answers0