使用Jersey客户端下载文件时内容为空 [英] Empty content-type while downloading file with Jersey client

查看:132
本文介绍了使用Jersey客户端下载文件时内容为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Jersey客户端下载文件. 我正在请求一个API,但是没有API源代码. 对于一个URL,API返回一个空的"Content-Type"标头(该标头存在但为空). 泽西岛不喜欢这样:

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:

无法解析"Content-Type"标头值:"

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

如果可能的话,我想保留泽西岛的客户

I'd like to keep the Jersey client if possible

  • API是否应该返回空的内容类型?
  • 我可以在请求中添加任何标头来解决问题吗?我尝试了内容类型并接受但没有成功.

推荐答案

您可以在收到响应后 手动设置Content-Type标头.

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);

这篇关于使用Jersey客户端下载文件时内容为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆