Created
April 10, 2015 06:25
-
-
Save omegachien/1ed90db2d442cc38c5d5 to your computer and use it in GitHub Desktop.
Volley POST v1.1
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
HashMap<String, String> params = new HashMap<String, String>(); | |
float price = 15.0f; | |
int userId = 1; | |
String url = "greenroom.com.my/api/v1/price/update"; | |
//Construct signature and POST param | |
params.put("price", price); | |
params.put("user_id", userId); | |
Log.d("URL", url); | |
JsonObjectRequest req = new JsonObjectRequest(url, new JSONObject( | |
params), new Response.Listener<JSONObject>() { | |
@Override | |
public void onResponse(JSONObject response) { | |
//success, maybe show message telling user? | |
} | |
}, new Response.ErrorListener() { | |
@Override | |
public void onErrorResponse(VolleyError error) { | |
NetworkResponse response = error.networkResponse; | |
if (response != null && response.data != null) { | |
switch (response.statusCode) { | |
case 400: | |
json = new String(response.data); | |
try { | |
JSONObject obj = new JSONObject(json); | |
JSONObject objError = obj.getJSONObject("error"); | |
String message = objError.getString("message"); | |
Log.d("ERROR VOLLEY", message); | |
} catch (Exception e) { | |
} | |
break; | |
} | |
} | |
} | |
}); | |
// add the request object to the queue to be executed | |
sma.addToRequestQueue(req); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment