In my android app user enters username and password and i check the response after i sent them to server . If the result is positive i am changing the activity and sending different requests. But server responds me as "You have to log in." despite i am creating only one HttpURLConnection. How can i solve this problem.
private static HttpURLConnection conn;
private static String _sessionIdCookie;
This method for getting the results of my requests.
public void fetchJSON(){
Thread thread = new Thread(new Runnable(){
@Override
public void run() {
try {
URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
if (_sessionIdCookie != null)
conn.setRequestProperty("Cookie", _sessionIdCookie);
//I am getting sessionId from respond. Server send my session ID in JSON.
conn.setDoInput(true);
// Starts the query
conn.connect();
InputStream stream = conn.getInputStream();
String data = convertStreamToString(stream);
readAndParseJSON(data); //This function parses the data.
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
}