Android studio does not allow to connect my application to internet

1.3k Views Asked by At

Hey I'm doing a web service login to my app, I've tried to connect to the internet, but it fails.

I've used httpurl connection and at the time of execute openConnection() and getresponseCode() it omits the code in that line.

I also tried with

AsyncHttpclient but it also fails.

I do not know what I'm doing wrong, I've tried with my webpage on xampp and also with www.google.com

the first one wait for more or less 3 seconds and then says it failed. The second one, fails from the first execution.

I tried to enter to the internet with chrome in android and it works!

1

There are 1 best solutions below

0
Alen Smith On

Check if you added INTERNET permission on Manifest

Check if you are on a PROXY configuration

If problem still persist, Try this

Just create a WebServer class instance passing your context

WebServer server=new WebServer(getApplicationContext());

Now attach a listner to it

        server.setOnServerStatusListner(new WebServer.OnServerStatusListner() {
            @Override
            public void onServerResponded(String responce) {

            }

            @Override
            public void onServerRevoked() {

            }
        });

Now call the URL like Http GET reqest

server.connectWithGET("https://www.google.com/test.php?name=Eric");

Optionaly, If you are dealing with Http POST, Then create a DataRack

        List<DataRack> racks=new ArrayList<DataRack>();
        racks.add(new DataRack("name","Simon"));
        racks.add(new DataRack("age","40"));
        racks.add(new DataRack("location","Canada"));

And connect

server.connectWithPOST(MainActivity.this,"http://sangeethnandakumar.esy.es/PROJECTS/PUBLIC_SERVICE/posttest.php",racks);

You need to include this library : com.github.sangeethnandakumar:TestTube:v2.5.2

Full documentations here - https://github.com/sangeethnandakumar/TestTube