Advertisement
Guest User

Untitled

a guest
Jun 18th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. public void onClick(View view) {
  2. username = emailET.getText().toString();
  3. password = pwdET.getText().toString();
  4. AsyncHttpClient client = new AsyncHttpClient();
  5. RequestParams params = new RequestParams();
  6. params.put("username", username);
  7. params.put("password", password);
  8. client.post("http://10.0.3.2:3000/index", params, new TextHttpResponseHandler() {
  9. @Override
  10. public void onSuccess(int statusCode, Header[] headers, String res) {
  11. try {
  12. JSONObject obj = new JSONObject(res);
  13. if(obj.getString("success").equals("true")){
  14. Toast.makeText(getApplicationContext(),"Service connected", Toast.LENGTH_LONG);
  15. }
  16. } catch (JSONException e) {
  17. e.printStackTrace();
  18. Toast.makeText(getApplicationContext(),"Server not connected",Toast.LENGTH_LONG);
  19. }
  20. // called when response HTTP status is "200 OK"
  21. }
  22.  
  23. @Override
  24. public void onFailure(int statusCode, Header[] headers, String res, Throwable t) {
  25. // called when response HTTP status is "4XX" (eg. 401, 403, 404)
  26. Toast.makeText(getApplicationContext(),"Bad Request",Toast.LENGTH_LONG);
  27. }
  28. }
  29. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement