2018-03-10 android下提交数据(request)(二)

笔记如下

使用 开源框架 -------android-async-http-master

  • 首先开启权限

  • get
            AsyncHttpClient client = new AsyncHttpClient();

            client.get(path, new AsyncHttpResponseHandler() {

                //请求成功会被调用的
                @Override
                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                    //System.out.println(new String(responseBody));
                    tv_status.setText(new String(responseBody));
                }
                //请求失败时候会被调用的
                @Override
                public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable
                        error)
                {
                    error.printStackTrace(System.out);
                }
            });
  • post
            AsyncHttpClient client = new AsyncHttpClient();


            RequestParams params = new RequestParams();

            params.add("number",number);
            params.add("pwd",pwd);

            client.post(path,params,new AsyncHttpResponseHandler() {

                @Override
                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                    //System.out.println(responseBody);
                    tv_status.setText(new String(responseBody));
                }
                @Override
                public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable
                        error)
                {
                    error.printStackTrace(System.out);
                }
            });

你可能感兴趣的:(2018-03-10 android下提交数据(request)(二))