Closed Gobmichet closed 2 years ago
did you find ant solutions for that? @Gobmichet
Initialize Dio
with your custom header which is cost throughout the app.
dio = Dio(
BaseOptions(contentType: 'application/json', headers: {
"Custom-Header" : "Your header"
}),
);
Hello @Gobmichet, There are 2 ways to manage header using retrofit
_dio!.interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) async {
options.headers['token'] = 'token';
return handler.next(options);
},
),
);
@GET("/posts/{id}")
Future<PostDataById> getPostById(@Path("id") int id, @Header('Content-Type') String header);
I'll hope this will help you
Thank you!
Hi, and thanks for your work,
I have some trouble with @headers that i just can't see in the DevTools while debugging (0_o)
what's more i HAVE to add this in imports :
import 'package:dio/dio.dart' hide Headers;
because if i don't, Android studio yells at me saying @Headers are both declared in dart and retrofit packages... Is it normal ??? Do i do the good thing ?Just for tests i did implement in your github code the method below :
And while the request does work (see screenshot), there is no way i can have a look at headers i did add :( As you can see on the screenshot :: Request headers content-length [0]
Can you please help/explain me ? Thanks in advance.
PS :: what's more in a "real" project of mine, when i add a certain header i got a 403 forbidden but a 401 unauthorized if i remove it... So obviously there are headers that are added but still can't see any of them in the flutter devtools :(
PPS :: is there any other way/mean to debug my request ? catching the request and printing headers somewhere in the code maybe ?????