zoukankan      html  css  js  c++  java
  • Volley框架使用(POST)

    需要在MyApplication(继承Application)中配置;

    public static RequestQueue requestQueue;
        @Override
        public void onCreate() {
            super.onCreate();
            Volley.newRequestQueue(getApplicationContext());
        }
        public static RequestQueue getHttpQueues() {
            return requestQueue;
        }

    使用时:

    private void login() {
            String url = "POST地址";
            StringRequest request = new StringRequest(Request.Method.POST, url, this,this){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String,String> params = new HashMap<String, String>();
                    //添加登陆参数
                    return params;
                }
                @Override
                protected com.android.volley.Response<String> parseNetworkResponse(
                        NetworkResponse response) {
                    try {
                        Map<String, String> responseHeaders = response.headers;
                        //打印httpheader
                        L.i("responseHeaders",responseHeaders.toString());
                        String rawCookies = responseHeaders.get("Set-Cookie");
                        //打印cookie
                        L.i("rawCookies",rawCookies);
                        String dataString = new String(response.data, "UTF-8");
                        return com.android.volley.Response.success(dataString, HttpHeaderParser.parseCacheHeaders(response));
                    } catch (UnsupportedEncodingException e) {
                        return com.android.volley.Response.error(new ParseError(e));
                    }
                }
            };
            //加入请求队列
            MyApplication.getHttpQueues().add(request);
        }
    
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            //请求失败时处理
        }
    
        @Override
        public void onResponse(String s) {
            //请求成功时处理
        }
  • 相关阅读:
    vue项目index.html , main.js的关系
    vue项目是如何加载入口文件main.js的
    解决Mysql密码修改后不能登录的问题
    解决IDEA右侧maven不显示方法
    (转)sql语句定义和执行顺序
    关于我
    css中好用的clamp()函数
    vue中子组件使用$emit传值的种种情况
    我的大学 -詹书庭
    自定义组件使用v-model
  • 原文地址:https://www.cnblogs.com/Jsonlu/p/4804616.html
Copyright © 2011-2022 走看看