Yes, there is a way to add headers to a Retrofit API request without using an Interceptor. You can add headers directly to the method or the request using the @Headers annotation in Retrofit.
For example:
@Headers("Authorization: token123")
@GET("user")
Call<User> getUser();
This will add an "Authorization" header with the value "token123" to the GET request for the "user" endpoint.
You can also add multiple headers using the @Headers annotation with multiple values:
@Headers({
"Authorization: token123",
"Accept: application/json"
})
@GET("user")
Call<User> getUser();
This will add both "Authorization" and "Accept" headers to the GET request.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-02-15 11:00:00 +0000
Seen: 12 times
Last updated: Mar 16 '22
What does the "429 error" in the request response of Instabot mean?
Can migration files be executed in knex upon making an API request?
What is the process of performing a GET request while using OAuth1 authentication?
What does it mean when API Gateway gives a 503 Service Unavailable error?
How can Google OAuth be integrated with FastAPI?
How can Azure DevOps Pull Request and Jenkins be utilized within a corporate network?
How to make an httr SOAP API request using R?
Is it possible for someone to make FieldOutputRequestState functional in Abaqus Scripting?
What is the way to hold off until Flask handles all requests?
How can type hinting be implemented in JSDoc for the request body of an express js application?