When the request is sent through Postman I can see it is sending all Set-Cookie in response header. Example :
Set-Cookie : wfwaf-authcookie-b52dd4381520%...... expires=Fri, 04-Dec-2020 23:32:21 GMT; Max-Age=43200; path=/; secure; HttpOnly
Set-Cookie : woocommerce_items_in_cart=1; path=/
Set-Cookie : woocommerce_cart_hash=92e2c.......; path=/
Set-Cookie : wp_cocart_session_a9339f....; expires=Fri, 11-Dec-2020 11:32:21 GMT; Max-Age=604800; path=/; secure; HttpOnly
But in Retrofit I'm only getting 2 of them. Not all 4. The request url is : https://mywpwebsite.com/wp-json/wc/store/cart
my code for calling retrofit request:
public MutableLiveData<Resource<Cart> > getCartItems(HashMap<String,String> attribs, HashMap<String,String> headers) {
Log.d(TAG, "get cart items: being called");
final MutableLiveData cartitems = new MutableLiveData<>();
WCService service = getRetrofitInstance().create(WCService.class);
Call<Cart> call = service.getCartItems(attribs,headers);
call.enqueue(new Callback<Cart>() {
@Override
public void onResponse(Call<Cart> call, Response<Cart> response) {
Log.d(TAG,"fetched cartitems");
Log.d(TAG,"responsecode:"+response.code());
Log.d(TAG, "onResponse: headers: "+response.headers().toString());
Log.d(TAG, "onResponse: cookie : " + response.headers().toMultimap() .get("Set-Cookie").toString());
if (response.code() == 200) {
if (response.body() != null)
cartitems.setValue(WCRepository.Resource.success(response.body()));
else
cartitems.setValue(WCRepository.Resource.error("Something went wrong, please refresh", null));
} else {
try {
errorResponse er = new Gson().fromJson(response.errorBody().string(), errorResponse.class);
cartitems.setValue(WCRepository.Resource.error(er.getMessage(), er.getMessage()));
} catch (Exception e) {
cartitems.setValue(WCRepository.Resource.error("error: "+ e.getMessage(), null));
}
}
}
@Override
public void onFailure(Call<Cart> call, Throwable t) {
cartitems.setValue(null);
Log.d(TAG, "onFailure: "+t.getMessage());
}
});
return cartitems;
}
and
@GET("store/cart?")
Call<Cart> getCartItems(@QueryMap() Map<String,String> params, @HeaderMap() Map<String,String> headers);