HttpClient 方法 一定要加useLibrary 'org.apache.http.legacy'

   @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        MyTask task=new MyTask();
        task.execute("http://120.27.23.105/user/getDefaultAddr?uid=71");

    }

class MyTask extends AsyncTask<String,String,String>{


    @Override
    protected String doInBackground(String... strings) {

      HttpClient client=new DefaultHttpClient();
        HttpGet get=new HttpGet(strings[0]);

        try {
            HttpResponse execute = client.execute(get);
            if (execute.getStatusLine().getStatusCode()==200){

                HttpEntity entity = execute.getEntity();

                String s = EntityUtils.toString(entity);

                return s;

            }


        } catch (Exception e) {
            e.printStackTrace();
        }


        return null;
    }


    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        Gson gson=new Gson();
        Dateb dateb = gson.fromJson(s, Dateb.class);

        String code = dateb.getCode();
        String msg = dateb.getMsg();

        name.setText(code);
        froms.setText(msg);
    }


    }
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭