Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save benjaminsinzore/93a9e15ea8725cab98221fb835af6aaf to your computer and use it in GitHub Desktop.
Save benjaminsinzore/93a9e15ea8725cab98221fb835af6aaf to your computer and use it in GitHub Desktop.

Revisions

  1. @mstfldmr mstfldmr created this gist Mar 19, 2015.
    32 changes: 32 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    RequestQueue queue = Volley.newRequestQueue(context);
    //for POST requests, only the following line should be changed to

    StringRequest sr = new StringRequest(Request.Method.GET, "http://headers.jsontest.com/",
    new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
    Log.e("HttpClient", "success! response: " + response.toString());
    }
    },
    new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
    Log.e("HttpClient", "error: " + error.toString());
    }
    })
    {
    @Override
    protected Map<String,String> getParams(){
    Map<String,String> params = new HashMap<String, String>();
    params.put("user","YOUR USERNAME");
    params.put("pass","YOUR PASSWORD");
    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);