There are already some code snippets in the net, which show how it should work. For example this one.
My code doesn't work; and I'm also searching for a version to send the Cookie header dynamically (I mean only on specific requests - the login doesn't require it).
So my code:
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
// header
// httpClient.addInterceptor(chain -> cookie != null ? chain.proceed(chain.request().newBuilder().addHeader("Set-Cookie", cookie).build()) : chain.proceed(chain.request()));
httpClient.addInterceptor(chain -> chain.proceed(chain.request().newBuilder().addheader("Cookie", cookie).build()));
Retrofit retrofit = new Retrofit.Builder().baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
I'm not getting this header in my log!
--> POST [link] http/1.1
Content-Type: application/json; charset=UTF-8
Content-Length: 125
{// response object
My requests itself are retrofit-base; just an interface with parameters... nothing special where I could maybe change something I shouldn't to fix this error.
Has anybody a idea? And how can I make it dynamic? With the comment line?
I read, that retrofit supported the @Header
Annotation also as parameter. Support canceled?