Closed dumanps closed 8 years ago
Sorry, how can i send post request with using java http request? I want insert any value in my collection.have any example for this?
I'm trying do it with jersy lib like this:
Client jersyClient = getJersyClient(); WebTarget target = jersyClient.target("http://10.146.136.40/simpleFilesMongoDbTest/photo.files") FormDataBodyPart fileFormDataBodyPart = new FormDataBodyPart("file", Files.readAllBytes(path), MediaType.APPLICATION_OCTET_STREAM_TYPE); FormDataBodyPart fileNameFormDataBodyPart = new FormDataBodyPart("filename", path.getFileName().toString(), MediaType.APPLICATION_JSON_TYPE);
Response response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(multiPartEntity, multiPartEntity.getMediaType()));
and answer is 406 "http status code" : 406 , "http status description" : "Not Acceptable" , "message" : "This request does not contain any binary file"
But I have a byte[] - Files.readAllBytes(path)
have a look at integration test classes. they use apache http client library
for example see PostCollectionIT.java or for files GetFileHandlerIT.java
Thank you, I'll try to use Apache lib
Sorry, how can i send post request with using java http request? I want insert any value in my collection.have any example for this?
I'm trying do it with jersy lib like this:
Client jersyClient = getJersyClient(); WebTarget target = jersyClient.target("http://10.146.136.40/simpleFilesMongoDbTest/photo.files") FormDataBodyPart fileFormDataBodyPart = new FormDataBodyPart("file", Files.readAllBytes(path), MediaType.APPLICATION_OCTET_STREAM_TYPE); FormDataBodyPart fileNameFormDataBodyPart = new FormDataBodyPart("filename", path.getFileName().toString(), MediaType.APPLICATION_JSON_TYPE);
Response response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(multiPartEntity, multiPartEntity.getMediaType()));
and answer is 406 "http status code" : 406 , "http status description" : "Not Acceptable" , "message" : "This request does not contain any binary file"
But I have a byte[] - Files.readAllBytes(path)