美文网首页
2018-03-10 android下提交数据(request)

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

作者: 紫杉叶子 | 来源:发表于2018-03-12 10:46 被阅读0次
    笔记如下

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

    • 首先开启权限
    <uses-permission android:name="android.permission.INTERNET"/>
    
    • 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)

          本文链接:https://www.haomeiwen.com/subject/miyvfftx.html