Question

I am making REST request to login, but i cannot do some other requests as the server returns error 15 which means that i am not logged in. I have to Log in every time i make any request. I tried like this:

public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
    @Override
    protected Boolean doInBackground(Void... params) {
        String success;
       try {
            // Building Parameters
            List<NameValuePair> params1 = new ArrayList<NameValuePair>();
            params1.add(new BasicNameValuePair("user", username));
            params1.add(new BasicNameValuePair("pass", password));
            }

            // getting user details by making HTTP request
            JSONObject json = jsonParser.makeHttpRequest(
                   LOGIN_URL, "POST", params1);
            //make second request
            JSONObject json1 = 
                    jsonParser.getFollowers(FollowersFragment.FOLLOWERS_URL);

            success = json.getString("status");
            Log.d("success tag from json::: ", success);
            if (success.equals(TAG_SUCCESS)) {
           ...
        return true;
            }else if (success.equals(TAG_MESSAGE))
                {
            ... 
            }
        } catch (JSONException e) {
            Log.d("Login Failure!", e.toString());
        }        
        return false;
    }

The requests are made at the same moment, but i still get that i am not logged in. How do i make these two requests simultaneous?

Was it helpful?

Solution

I solved my issue by creating this variable global:

public static DefaultHttpClient httpClient = new DefaultHttpClient();

And i use GlobalData.httpClient inside my method where i make requests. And every time i want to make a request, i use httpClient, i do not create a new one. So that the the same connection is used every time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top