volley 发送post请求
2016-02-05 10:28
148 查看
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); }
相关文章推荐
- java中null和""的区别
- Java系统程序员修炼之道(转载于CSDN"流浪的鱼"大大)
- python selenium --调用js
- JSON 之JAVA 解析
- jquery 改变checkbox的值
- swing入门教程(二) 简单的swing小部件
- junit设计模式--组合模式
- junit设计模式--组合模式
- NodeJS、NPM安装配置步骤(windows版本)
- Getting started with Chrome Dev Editor
- python selenium --滚动条处理
- JSON 之GSON 解析
- PAT 1001
- html中导入.css 和 javascript
- 字符串 HDU 2054 A == B ?
- [3] CMake FAQ
- OGL浅学_雾效果
- Item 4: 知道怎么去看推导的类型
- JSON 之FastJson解析
- C++ 排序算法实现 及 性能比较