zoukankan      html  css  js  c++  java
  • Android 通过开源框架AsyncHttpClient进行get和post请求

    使用时无需将这些代码放入子线程去执行,因为其内部已经封装到一个线程中运行了!

    public void asyncHttpClientGet(View view) {
            AsyncHttpClient client = new AsyncHttpClient();
            client.get(
                    "http://10.0.2.2:8080/LoginServlet?username=张三&password=123",
                    new AsyncHttpResponseHandler() {
                        @Override
                        public void onSuccess(String response) {
                            Toast.makeText(MainActivity.this, response,
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
        }
    
        public void asyncHttpClientPost(View view) {
            AsyncHttpClient client = new AsyncHttpClient();
            RequestParams requestParams = new RequestParams();
            requestParams.add("username", "张三");
            requestParams.add("password", "123");
            client.post("http://10.0.2.2:8080/LoginServlet", requestParams,
                    new AsyncHttpResponseHandler() {
                        @Override
                        public void onSuccess(String response) {
                            Toast.makeText(MainActivity.this, response,
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
        }

    我所用的是1.4.4版本的jar包

  • 相关阅读:
    valueOf与toString
    责任链模式
    Js中Symbol对象
    Vue路由懒加载
    updatedb命令
    策略模式
    Docker(3)- Centos 7.x 下 Docker 镜像加速配置
    Vmware
    Docker(2)- Centos 7.x 下安装 Docker
    Docker(1)- 什么是 Docker
  • 原文地址:https://www.cnblogs.com/wuyou/p/3427901.html
Copyright © 2011-2022 走看看