简体   繁体   English

使用Jersey客户端下载文件时内容为空

[英]Empty content-type while downloading file with Jersey client

I'm trying to download a file with the Jersey client. 我正在尝试使用Jersey客户端下载文件。 I'm requesting an API, and I don't have API source code. 我正在请求一个API,但是没有API源代码。 For one URL, the API returns an empty "Content-Type" header (the header is present but empty). 对于一个URL,API返回一个空的“ Content-Type”标头(该标头存在但为空)。 Jersey does not like this: 泽西岛不喜欢这样:

Unable to parse "Content-Type" header value: "" 无法解析“ Content-Type”标头值:“”

I'd like to keep the Jersey client if possible 如果可能,我想保留泽西岛的客户

  • Is an API supposed to return an empty content-type? API是否应该返回空的内容类型?
  • Is there any header I can add to my request that may solve the problem? 我可以在请求中添加任何标题来解决问题吗? I tried content-type and accept without success. 我尝试了内容类型并接受但没有成功。

You can set the Content-Type header manually after you receive the response. 您可以收到响应手动设置Content-Type标头。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jersey客户端将内容类型标题设置为text / plain - Jersey Client set content-type header as text/plain Jersey:根据文件扩展名或InputStream设置响应内容类型? - Jersey: Set response content-type based on file extension or InputStream? Jersey REST-Client WebTarget - 找不到内容类型的 MessageBodyReader - Jersey REST-Client WebTarget - Unable to find a MessageBodyReader of content-type 在球衣休息api下载空的csv文件 - Empty csv file downloading in jersey rest api 内容类型为“ *”的JAX-RS Jersey读取实体 - JAX-RS Jersey Read entity with Content-Type “*” 在Content-Type中指定charset时,Jersey和@FormParam无法正常工作 - Jersey and @FormParam not working when charset is specified in the Content-Type Jersey:阅读内容类型:简单/文本响应为XML - Jersey: Reading Content-Type:plain/text response as XML 从Jersey迁移到RESTEasy时,内容类型为空。 - Null content-type when migrating from Jersey to RESTEasy. 在apache http客户端中,如何将StringBody中的Content-Type保留为空或null? - In apache http client, how to keep the Content-Type in a StringBody as empty or null? 如何在使用RestTemplate(来自其他客户端)时为分段上传中的文件设置内容类型 - How to set content-type for the file in multipart upload when using RestTemplate (from a rest client)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM