Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onClick(View view) {
- username = emailET.getText().toString();
- password = pwdET.getText().toString();
- AsyncHttpClient client = new AsyncHttpClient();
- RequestParams params = new RequestParams();
- params.put("username", username);
- params.put("password", password);
- client.post("http://10.0.3.2:3000/index", params, new TextHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, String res) {
- try {
- JSONObject obj = new JSONObject(res);
- if(obj.getString("success").equals("true")){
- Toast.makeText(getApplicationContext(),"Service connected", Toast.LENGTH_LONG);
- }
- } catch (JSONException e) {
- e.printStackTrace();
- Toast.makeText(getApplicationContext(),"Server not connected",Toast.LENGTH_LONG);
- }
- // called when response HTTP status is "200 OK"
- }
- @Override
- public void onFailure(int statusCode, Header[] headers, String res, Throwable t) {
- // called when response HTTP status is "4XX" (eg. 401, 403, 404)
- Toast.makeText(getApplicationContext(),"Bad Request",Toast.LENGTH_LONG);
- }
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement