Welcome to ZaiZheLe Developer Zone-Open, Learning and Share
Welcome To Ask or Share your Answers For Others


0 votes
in Technique[技术] by (71.8m points)

api - cz.msebera.android.httpclient.client.HttpResponseException:

I face this problem and I don't know how to solve it here is my code: "cz.msebera.android.httpclient.client.HttpResponseException"

it going immediately to the OnFailure method: In both of the classes in sign in class and in sign up, I face the same error.

 signIn.setOnClickListener(v -> {

        //login onClickListener
        userString = email.getText().toString();
        passwordString = password.getText().toString();

        if(TextUtils.isEmpty(userString) || TextUtils.isEmpty(passwordString)){
            Toast.makeText(LoginPage.this,"Please fill email and password", Toast.LENGTH_LONG).show();


        RequestParams params = new RequestParams();

        params.put("email", userString);
        params.put("password", passwordString);

        RestClient.post("/client/sign-in", params, new AsyncHttpResponseHandler() {

            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {

                try {
                    String res = new String(responseBody, "UTF-8");

                    JSONObject resObj = new JSONObject(res);

                    if (resObj.getString("sign-in") == "true") {

                        Toast.makeText(LoginPage.this, " Login Success", Toast.LENGTH_SHORT).show();
                        Intent i = new Intent(LoginPage.this, Profile.class);

                } catch (Exception ex) {
                    //Toast to catch

                    Toast.makeText(LoginPage.this, " Login Exception", Toast.LENGTH_SHORT).show();



            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                Toast.makeText(LoginPage.this , " Login Failure" , Toast.LENGTH_SHORT).show();


and here is my connection class:

public class RestClient {

private final static String BASE_URL = "http://***.***.***.***:8081/**"; // the dns here

private static AsyncHttpClient client = new AsyncHttpClient();

public static void get(String url , RequestParams params , AsyncHttpResponseHandler responseHandler){

    client.get(getAbsoluteURL(url) ,params,responseHandler);

public static void post(String url , RequestParams params , AsyncHttpResponseHandler responseHandler){

    client.setConnectTimeout(20000); //set the timeout in milliseconds
    client.post(getAbsoluteURL(url) ,params,responseHandler);


private static String getAbsoluteURL (String relativeURL){return BASE_URL+relativeURL;}


I tried also without the Timeout and still the same problem I make sure of the spelling in the API I tested it in postman and it's working well

Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Welcome to ZaiZheLe Developer Zone-Open, Learning and Share