简体   繁体   中英

Empty content-type while downloading file with Jersey client

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM