Last active
March 6, 2016 13:36
-
-
Save thedoapps/ab1bb202f036d750e5b3 to your computer and use it in GitHub Desktop.
How to implement Web services consumption POST using "x-www-form-urlencode"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RequestQueue requestQueue = Volley.newRequestQueue(this); | |
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest( | |
Request.Method.POST, | |
"github.com/api/login", | |
new Response.Listener<JSONObject>() { | |
@Override | |
public void onResponse(JSONObject response) { | |
Log.e("LOGIN", response.toString()); | |
} | |
}, | |
new Response.ErrorListener() { | |
@Override | |
public void onErrorResponse(VolleyError error) { | |
Log.e("LOGIN ERROR", error.toString()); | |
} | |
}) | |
{ | |
@Override | |
public byte[] getBody() { | |
try | |
{ | |
final String body = "&email=" + "[email protected]" + | |
"&password=" + "test"; | |
return body.getBytes("utf-8"); | |
} | |
catch (Exception ex) { | |
Log.e("getBodyEx", ex.toString()); | |
} | |
return null; | |
} | |
@Override | |
public String getBodyContentType() { | |
return "application/x-www-form-urlencoded"; | |
} | |
@Override | |
public Map<String, String> getHeaders() throws AuthFailureError { | |
Map<String, String> headers = new HashMap<String, String>(); | |
headers.put("Accept", "application/json"); | |
return headers; | |
} | |
}; | |
requestQueue.add(jsonObjectRequest); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment