Facing Errors In Simple HTTP Request

use

Value(con.getInputStream().toString);
1 Like


@mohamed_tamer

1 Like

Sorry, that was wrong.try this :slightly_smiling_face::

String inputLine;
String output = "";
        while ((inputLine = in.readLine()) != null) {
            output = output + inputLine;
}
Value( output );
1 Like

but where is inputstream

1 Like

i think it should rd.readLine But i don't know much more i am trying this first time

1 Like

The input stream is the

Which is rd with your code.
So You can change it the code to

    String inputLine;
In
    String output = "";
            while ((inputLine = rd.readLine()) != null) {
                output = output + inputLine;
    }
    Value( output );
1 Like

yeah, thanks

1 Like

now i have 5 errors :sob: :sob:
can i pm you my code??

1 Like

Yes you can

1 Like

sent

1 Like

Be aware that on Android 2.3 and higher you will likely get a NetworkOnMainThreadException due to the fact that you're trying to do an HTTP request on the main thread. Typically you need to launch the HTTP request on a separate thread using something like AsynchUtil. See the Web component as an example.

1 Like

@ewpatton thanks sir for your reply. I will try your suggestion

Hi @ewpatton sir I again tried to do as you said but my app is crashing after exporting.

public void Get(final String website) {
    AsynchUtil.runAsynchronously(new Runnable() {
        @Override
        public void run() {
            try {
                URL url = new URL(website);
                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setRequestMethod("GET");
                BufferedReader bufferedReader = null;
                if (httpURLConnection.getResponseCode() == 200) {
                    bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
                } else {
                    bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getErrorStream()));
                }
                StringBuilder stringBuilder = new StringBuilder();
                String str;
                while ((str = bufferedReader.readLine()) != null) stringBuilder.append(str);
                bufferedReader.close();

                final String data = stringBuilder.toString();
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Getdata(data);
                    }
                });
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

}

Does it crash when app open or when you call the block?

1 Like

It is crashing when I put that block. (After button clicking)

Please try this if you want a simple get request. This works fine. :slightly_smiling_face:
Also, see logs what is the error occurred. Use log reader extension, it helped me also (ask sunny)

1 Like

oh thanks @KUMARASWAMY_B.G

1 Like

Still same happening :pleading_face: :pleading_face:

1 Like

That shouldn't happen.
Can you post the logs here?

1 Like

Something is wrong in my side. Same extension was compiled by @KUMARASWAMY_B.G and it worked but when I compiled it crashed again. I will reinstall sources.

1 Like