Guest User

Untitled

a guest
Jun 22nd, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. public void fnCallLoginAPI() {
  2. try {
  3. //DEMO URL
  4. //final String URL="http://demo.io/api/api.php?m=login";
  5. //LIVE URL
  6. final String URL = "https://www.live.com/shop/api/api.php?m=login";
  7. final String requestBody = "email=abc.b@xyz.com" + "&password=43443==" + "&strPlatform=i" + "&strDeviceToken=null";
  8. StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
  9. @Override
  10. public void onResponse(String response) {
  11. String strResponse = response;
  12. System.out.println("THE RESPONSE IS in PROFILE IS" + response);
  13. }
  14. },
  15. new Response.ErrorListener() {
  16. @Override
  17. public void onErrorResponse(VolleyError error) {
  18.  
  19. }
  20. })
  21. {
  22. @Override
  23. public Map<String, String> getHeaders() throws AuthFailureError {
  24. Map<String, String> headers = new HashMap<>();
  25. headers.put("Cookie", "PHPSESSID=" + sessionID);
  26. return headers;
  27. }
  28. @Override
  29. public byte[] getBody() throws AuthFailureError {
  30. byte[] body = new byte[0];
  31. try {
  32. System.out.println("THE REQIEST BODY IS" + requestBody);
  33. body = requestBody.getBytes("UTF-8");
  34. } catch (UnsupportedEncodingException e) {
  35. Log.e("TAG", "Unable to gets bytes from JSON", e.fillInStackTrace());
  36. }
  37. return body;
  38. }
  39. };
  40.  
  41. AppApplication.getInstance().addToRequestQueue(stringRequest, "assignment");
  42. } catch (Exception e) {
  43.  
  44. }
  45. }
  46.  
  47. public void fnCallCateGoryAPI(){
  48. try { final String URL ="https://www.live.com/shop/api/api.php?m=getcategories";
  49. StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
  50. @Override
  51. public void onResponse(String response) {
  52. String strResponse = response;
  53. System.out.println("THE RESPONSE IS in PROFILE IS" + response);
  54. JSONObject jsonObj = null;
  55. try {
  56. jsonObj = new JSONObject(strResponse);
  57. sessionID = jsonObj.optString("session_id");
  58. System.out.print("sessionID" + sessionID);
  59. } catch (JSONException e) {
  60. e.printStackTrace();
  61. }
  62. }
  63. },
  64. new Response.ErrorListener() {
  65. @Override
  66. public void onErrorResponse(VolleyError error) {
  67. }
  68. })
  69. {
  70. };
  71.  
  72. AppApplication.getInstance().addToRequestQueue(stringRequest, "assignment");
  73. } catch (Exception e) {}
  74. }}
Add Comment
Please, Sign In to add comment