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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With