Empty content-type while downloading file with Jersey client

旧巷老猫 提交于 2019-12-24 20:00:31

问题


I'm trying to download a file with the Jersey client. I'm requesting an API, and I don't have API source code. For one URL, the API returns an empty "Content-Type" header (the header is present but empty). Jersey does not like this:

Unable to parse "Content-Type" header value: ""

I'd like to keep the Jersey client if possible

  • Is an API supposed to return an empty content-type?
  • Is there any header I can add to my request that may solve the problem? I tried content-type and accept without success.

回答1:


You can set the Content-Type header manually after you receive the response.

Response res = target.request().get();
res.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, "application/octect-stream");
InputStream file = res.readEntity(InputStream.class);


来源:https://stackoverflow.com/questions/51389255/empty-content-type-while-downloading-file-with-jersey-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!