1

I try to connect to an url, one simple because after i want to connect to a server. For this i have

String urlServer = "http://www.google.com";
URL url = new URL(urlServer);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
outputStream = new DataOutputStream( connection.getOutputStream() );

The last line goes to the catch exception. I don't know what happens, I have also tried with this

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.0.0.1", 8080));
conn = new URL(urlString).openConnection(proxy);

and it gives me

true

The LogCat gives me

android.os.NetworkOnMainThreadException
manolodewiner
  • 504
  • 3
  • 26

1 Answers1

0

Put your code in asynctask...

public class Sample extends AsyncTask<String, String, String>{

    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub
        return null;
    }

}

just put your lines related to network in the doInBackground.

Sar
  • 550
  • 4
  • 18