I read about request interceptors and what not but no clue how to really use them to obtain cookies... I am sending the cookie like so from nodejs...
res.cookie('userid', user._id, { maxAge: 86400000, signed: true, path: '/' });
And in my android client - I have this set up so far for my RestApiManager
public class RestApiManager {
private static final String API_URL = "ip: port";
private static final RestAdapter REST_ADAPTER = new RestAdapter.Builder()
.setEndpoint(API_URL)
.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
//Call interface
public interface AsynchronousApi {
//Login User
@FormUrlEncoded
@POST("/login")
public void loginUser(
@Field("loginName") String loginName,
@Field("password") String password,
Callback<UserResponse> callback);
//Profile Picture
@Multipart
@POST("/profilePicture")
public void uploadProfilePicture(
@Part("photo") TypedFile photo,
@Part("userId") String userId,
Callback<UserResponse> callback); //success thumbnail to picasso
}
//create adapter
private static final AsynchronousApi ASYNCHRONOUS_API = REST_ADAPTER.create(AsynchronousApi.class);
//call service to initiate
public static AsynchronousApi getAsyncApi() {
return ASYNCHRONOUS_API;
}
}
Separate cookie class:
public class ApiCookie implements RequestInterceptor{
// cookie use
private String sessionId;
public ApiCookie() {
}
//COOKIE BELOW
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public void clearSessionId() {
sessionId = null;
}
@Override
public void intercept(RequestFacade requestFacade) {
setSessionId();
}
}
trying to figure out how to obtain the cookie and be able to send it with future requests, so I do not need to include a userId field?
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
somewhere – Archineokhttp
as an underlying http-transport implementation. This is the way I handle cookies in my apps. – ArchineonCreate
method of my customApplication
class – Archine