zoukankan      html  css  js  c++  java
  • 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);
    }
    

      

  • 相关阅读:
    HDU1398Square Coins(母函数)
    HDU2079选课时间(母函数)
    HDU1028Ignatius and the Princess III(母函数)
    POJ1061青蛙的约会(扩展欧几里得)
    POJ1189钉子和小球(DP)
    POJ1179Polygon(DP)
    POJ2001Shortest Prefixes(字典树)
    POJ1157 LITTLE SHOP OF FLOWERS
    POJ3630Phone List(字典树)
    亲和串(HDU2203)
  • 原文地址:https://www.cnblogs.com/likwo/p/3495577.html
Copyright © 2011-2022 走看看