keep the active session

keep the active session

I have a question, Could you help me or tell me the best way to connect to a REST API which requires to keep the active session?
It means,  First I have to call a login method to access other methods in the API.

My code is:
                //CREATE THE HEADER PARAMETERS THE REST METHOD NEEDS
mapHeaderParameters = Map();
mapHeaderParameters.put("Content-Type","application/json");
mapHeaderParameters.putAll(mapParametersRestMethod);
//
//CALL TO METHOD REST
                //
                // LOGIN METHOD
mapApiResponse = postUrl(strUrlWebservicesFslso+strRestMethod,mapHeaderParameters,false);

                 // RESPONSE "SUCCESS"
mapResponse.put("PostResponses",mapApiResponse.get("responseText"));

                // STATES METHOD
mapApiResponse = getUrl(strUrlWebservicesFslso+"States", false);
                // RESPONSE " Unauthorized: Access is denied due to invalid credentials."
                mapResponse.put("GetResponse",mapApiResponse.get("responseText"));