Reputation: 19428
I'm trying to implement the following curl request using the jersey client
curl -H "Content-Type:application/json" -H "Authorization:Bearer 7est6xAiAYrhGmJyUkUKemz2yG_Qqn5RW5FCW1Iq1NLs6khyCMHQ" -X POST -d @example.json http://api.com/v1/jobs/
Here is the json
{
image_url : abc
}
Here is the jersey implementation
WebResource resource = Client.create(new DefaultClientConfig()).resource("http://api.com/v1/jobs");
WebResource.Builder builder = resource.accept(MediaType.APPLICATION_JSON);
builder.accept(MediaType.APPLICATION_JSON);
builder.header(HttpHeaders.AUTHORIZATION, "Bearer 7est6xAiAYrhGmJyUkUKemz2yG_Qqn5RW5FCW1Iq1NLs6khyCMHQ");
String input = "{\"image_url\": \"abc\"}";
ClientResponse output = builder.post(ClientResponse.class, input);
This give me a 400 Bad request error. Where am I going wrong???
Upvotes: 0
Views: 1849
Reputation: 66
You added Accept header 2 times and missed Content-Type in the code. Add below code it will work.
builder.type(MediaType.APPLICATION_JSON);
Upvotes: 1