Reputation: 1766
I am using Resteasy client proxy framework to talk to a REST API. I have defined some methods on the proxy interface but unfortunately, I have some issues related to Content-Type not being set properly when sending http requests, which gives me an http 400 (Bad Request) error code since the remote API is expecting the Content-type header param to be application/json.
Here is how it looks like :
@Path("/")
public interface RestAPIClient {
@POST
@Path("/send")
String send(@CookieParam("token") String token, @FormParam("name") String id, @FormParam("message") String message, @FormParam("emails") List<String> emails);
}
is there a way to set the "Content-type" header as "application/json" directly at the proxy interface level ? using some annotations maybe ?
thanks
Upvotes: 3
Views: 4420
Reputation: 61
As well as using:
@Consumes(MediaType.APPLICATION_JSON)
you need to ensure there is actually content in the body of the request (not just params).
If there is no content, then the Content-Type header won't be set.
Upvotes: 0
Reputation: 1178
I you try a
@Consumes(MediaType.APPLICATION_JSON)
on the POST ?
Take care of many things : you need to have an "entity" object who is send in the method (not @CookieParam, or @FormParam). And in
So your method must be like :
@POST
@Path("/auth")
@Consumes(MediaType.APPLICATION_JSON)
ConnectionInformation auth(@CookieParam("name") String name, @CookieParam("password") String password, MyJSONObject entity);
and "entity" will produce the
Content-Type: application/json
you need.
Upvotes: 2