Reputation: 548
I want to pass a header to each POST request in a retrofit api . Since i have lots of methods hear, i can't copy/paste the header information for every method.
public interface ApiInterface {
String[] header = {"Accept:application/json",
"apiKey:12345",
"Content-Type:application/json"};
@Headers(header)
@POST("signup?")
Call<SignupResponse> createUser(@Body SignupData signupData);
@Headers(header)
@POST("another")
....
}
The header variable in @HEADER creates this error:
Attribute must be constant
How can i solve the problem?
Upvotes: 2
Views: 856
Reputation: 1007359
Use:
@Headers({"Accept:application/json",
"apiKey:12345",
"Content-Type:application/json"})
@POST("another")
See the "Header Manipulation" section of the Retrofit documentation.
Upvotes: 1
Reputation: 3424
Try this
@Headers({"Accept:application/json",
"apiKey:12345",
"Content-Type:application/json"})
@POST("signup?")
Call<SignupResponse> createUser(@Body SignupData signupData);
Upvotes: 2