• volley 发送post请求


    public static void postNewComment(Context context,final UserAccount userAccount,final String comment,final int blogId,final int postId){
        mPostCommentResponse.requestStarted();
        RequestQueue queue = Volley.newRequestQueue(context);
        StringRequest sr = new StringRequest(Request.Method.POST,"http://api.someservice.com/post/comment", new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                mPostCommentResponse.requestCompleted();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mPostCommentResponse.requestEndedWithError(error);
            }
        }){
            @Override
            protected Map<String,String> getParams(){
                Map<String,String> params = new HashMap<String, String>();
                params.put("user",userAccount.getUsername());
                params.put("pass",userAccount.getPassword());
                params.put("comment", Uri.encode(comment));
                params.put("comment_post_ID",String.valueOf(postId));
                params.put("blogId",String.valueOf(blogId));
     
                return params;
            }
     
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String,String> params = new HashMap<String, String>();
                params.put("Content-Type","application/x-www-form-urlencoded");
                return params;
            }
        };
        queue.add(sr);
    }
     
    public interface PostCommentResponseListener {
        public void requestStarted();
        public void requestCompleted();
        public void requestEndedWithError(VolleyError error);
    }
    

      

  • 相关阅读:
    Linux链接库一(动态库,静态库,库放在什么路径下)
    scp指令的学习
    注册表语法
    汇编指令
    PS7.0快捷键和使用技巧
    Lrc歌词-开发标准
    VBS 创建快捷方式
    LDAP属性对照表
    按键精灵对VBS的支持
    英寸、磅等单位的换算
  • 原文地址:https://www.cnblogs.com/likwo/p/3495577.html
Copyright © 2020-2023  润新知