When you add a request to the queue, this request is executed asynchronously. This means that it is not executed in the order in which you read it, it happens in another thread and will eventually return.
protected Response<String> parseNetworkResponse(NetworkResponse response) { System.out.println(response.headers.get("Set-Cookie")); (1) phpsessid = response.headers.get("Set-Cookie"); (2) return super.parseNetworkResponse(response); }
This returns the body of the response - from what I read in your code, it looks like you want to return the value of the "Set-Cookie" header. You can do it as follows:
protected Response<String> parseNetworkResponse(NetworkResponse networkResponse) { String sessionId = response.headers.get("Set-Cookie"); com.android.volley.Response<String> result = com.android.volley.Response.success(sessionId, HttpHeaderParser.parseCacheHeaders(networkResponse)); return result; }
This will return the value of the Set-Cookie header to your onResponse method:
new Response.Listener<String>() { @Override public void onResponse(String response) { System.out.println(response); } }
A better idea would be to pass the listener with success / failure when calling getSessionId . This way you can easily access the result in the calling class:
public void getSessionId(Context context, final Response.Listener<String> successListener, Response.ErrorListener failureListener) { RequestQueue queue = Volley.newRequestQueue(context);
Edit:
Now you can call it like this:
Login login = new Login(); login.getSessionId(this, new Response.Listener<String>() { @Override public void onResponse(String response) {
source share