Advertisement
Guest User

Untitled

a guest
Sep 1st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. public void postEmailandPassword(final String email, final String data) {
  2.  
  3. StringRequest authenticateRequest = new StringRequest(Request.Method.POST, Constants.AUTHENTICATE_URL,
  4. new Response.Listener<String>() {
  5. @Override
  6. public void onResponse(String response) {
  7. Log.e("response", response.toString());
  8. if(response.trim().equals("success")){
  9. // openProfile();
  10. }else{
  11. Log.e("response", response.toString());
  12.  
  13. Toast.makeText(LoginActivity.this,response,Toast.LENGTH_LONG).show();
  14. }
  15. }
  16. },
  17. new Response.ErrorListener() {
  18.  
  19. @Override
  20. public void onErrorResponse( VolleyError volleyError ) {
  21. try {
  22. String responseBody = new String( volleyError.networkResponse.data, "utf-8" );
  23. JSONObject jsonObject = new JSONObject( responseBody );
  24. } catch ( JSONException e ) {
  25. //Handle a malformed json response
  26. } catch (UnsupportedEncodingException error){
  27.  
  28. }
  29. }
  30.  
  31. }){
  32.  
  33. @Override
  34. protected Map<String, String> getParams() throws AuthFailureError {
  35. Map<String,String> map = new HashMap<String,String>();
  36. map.put("email",email);
  37. map.put("password",data);
  38. return map;
  39. }
  40.  
  41. @Override
  42. public Map<String, String> getHeaders() throws AuthFailureError {
  43. Map<String, String> params = new HashMap<String, String>();
  44. params.put("x-session-id", "sessie-random-string-proshore");
  45. params.put("Authorization", "Basic cHJvc2hvcmU6c2hvcmVwcm8=");
  46. params.put("x-user-id", "22320");
  47. params.put("Accept-Language", "nl");
  48. params.put("Content-Type", "application/json; charset=utf-8");
  49. return params;
  50. }
  51. };
  52.  
  53. RequestQueue requestQueue = Volley.newRequestQueue(this);
  54. requestQueue.add(authenticateRequest);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement