Skip to content

Instantly share code, notes, and snippets.

@smurfpandey
Forked from mombrea/volley-POST-example.java
Last active December 13, 2019 12:06
Show Gist options
  • Save smurfpandey/6bd352855ea5265bd948 to your computer and use it in GitHub Desktop.
Save smurfpandey/6bd352855ea5265bd948 to your computer and use it in GitHub Desktop.
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);
}
@ijazbesant
Copy link

java platform really a best things to learn a high level languages and I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.

java training in bangalore

@adam12345678925555
Copy link

adam12345678925555 commented Sep 27, 2017

Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site. Besant Technologies offers the best Amazon Web Services Training in Bangalore with the aid of the most talented and well experienced professionals. Our instructors are working in Amazon Web Services and related technologies for quite a number of years in leading multi-national companies around the world.

@saibk
Copy link

saibk commented Oct 6, 2017

Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks; from every one of us.

Java Training in Chennai|

@ijazbesant
Copy link

Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

Selenium Training in Chennai

Selenium Training in Bangalore

@pubgmahi
Copy link

Excellent blog! The content is so strong and informative.Thanks for sharing such useful post.
Java training in Chennai

@samso140
Copy link

thanks for this wonderful blog that you've posted on this page.great effort and attainment of such a great information very much interest about your blog.keep it up.
Java Training in Chennai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment