I tried to upload a document to a document server with
Jersey. But curiously I can't set a header value. If I set the value as query param(server supports it) all works fine. But I wan't set it in the header. Here is my Java Code:
Client client =ClientBuilder.newClient()
.register(JacksonFeature.class)
.register(MultiPartFeature.class);
WebTarget webTarget=client.target("http://.../documents").queryParam("Token",token);
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("filedata", file, MediaType.APPLICATION_OCTET_STREAM_TYPE);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
multiPart.bodyPart(fileDataBodyPart);
Response response=webTarget.request(MediaType.APPLICATION_JSON_TYPE)
.header("Token",token)
.post(Entity.entity(multiPart,multiPart.getMediaType()));
I tried the same in Ruby and it works for the same URL with the same values and the Token param in the header:
require 'rest-client'
...
resp=RestClient.post url, JSON.generate(conversion_options), {content_type: :json,
accept: :json,
Token: token}
...
Is there a bug in Jersey for setting headers? My version is 2.22.2.
Thanks for helpful comments.
What I have tried:
Tried it with Ruby, in upper and lower and diverse possible solutions with Jersey.