HTTP doesn't work in Android emulator

后端 未结 3 2057
故里飘歌
故里飘歌 2020-12-01 17:20

I tried multiple HTTP classes (HttpURLConnection, HTTPClient and others) but they don\'t work in emulator. Then I decided to test that on my phone

3条回答
  •  甜味超标
    2020-12-01 17:20

    You disable the strict mode using following code:

    if (android.os.Build.VERSION.SDK_INT > 9) {
    StrictMode.ThreadPolicy policy = 
    new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    }
    

    This is not recommended: use the AsyncTask interface.

    Link of AsyncTask

    Link of another reference

提交回复
热议问题