找到请求类型 [java.lang.Long] 的 HttpMessageConverter
HttpMessageConverter found for request type [java.lang.Long]
SpringBoot
RestTemplate 转换器添加 FormHttpMessageConverter.java 和 StringHttpMessageConverter 以及 ResourceHttpMessageConverter 和 ByteArrayHttpMessageConverter,
Http client Long in params: parts.add("time", time);
org.springframework.http.converter.HttpMessageNotWritableException: Could not write request: no suitable HttpMessageConverter found for request type [java.lang.Long]
at org.springframework.http.converter.FormHttpMessageConverter.writePart(FormHttpMessageConverter.java:422)
at org.springframework.http.converter.FormHttpMessageConverter.writeParts(FormHttpMessageConverter.java:393)
at org.springframework.http.converter.FormHttpMessageConverter.writeMultipart(FormHttpMessageConverter.java:373)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:277)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:95)
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:948)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:733)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:670)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:414)
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_FORM_URLENCODED));
headers.setAcceptCharset(Collections.singletonList(CharsetUtil.CHARSET_UTF_8));
FileSystemResource zipFile = new FileSystemResource(new File(file.getAbsolutePath()));
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
Long time = System.currentTimeMillis();
parts.add("time", time);
parts.add("md5", SecureUtil.md5(time + "234234").toUpperCase());
parts.add("file", zipFile);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(parts, headers);
什么HttpMessageConverter可以支持Long?
默认情况下,以下消息转换器在 spring 中启用:
ByteArrayHttpMessageConverter – converts byte arrays
StringHttpMessageConverter – converts Strings
ResourceHttpMessageConverter – converts org.springframework.core.io.Resource for any type of octet stream
SourceHttpMessageConverter – converts javax.xml.transform.Source
FormHttpMessageConverter – converts form data to/from a MultiValueMap<String, String>.
Jaxb2RootElementHttpMessageConverter – converts Java objects to/from XML (added only if JAXB2 is present on the classpath)
MappingJackson2HttpMessageConverter – converts JSON (added only if Jackson 2 is present on the classpath)
MappingJacksonHttpMessageConverter – converts JSON (added only if Jackson is present on the classpath)
AtomFeedHttpMessageConverter – converts Atom feeds (added only if Rome is present on the classpath)
RssChannelHttpMessageConverter – converts RSS feeds (added only if Rome is present on the classpath)
收到新请求时,Spring 将使用“接受”header 来确定响应with.In 您的情况所需的媒体类型,FormHttpMessageConverter
是spring中默认选择的转换器,因为您已经指定内容type.When写入多部分数据,此转换器使用其他HttpMessageConverters
写入相应的MIME部分。FormHttpMessageConverter
class 找不到 Long 类型的消息转换器。因此,您可以尝试将 Long 转换为字符串并将其分配给像 :
这样的部分
Long time = System.currentTimeMillis();
parts.add("time", String.valueOf(time));
parts.add("md5", SecureUtil.md5(time + "234234").toUpperCase());
parts.add("file", zipFile);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(parts, headers);
SpringBoot
RestTemplate 转换器添加 FormHttpMessageConverter.java 和 StringHttpMessageConverter 以及 ResourceHttpMessageConverter 和 ByteArrayHttpMessageConverter,
Http client Long in params: parts.add("time", time);
org.springframework.http.converter.HttpMessageNotWritableException: Could not write request: no suitable HttpMessageConverter found for request type [java.lang.Long]
at org.springframework.http.converter.FormHttpMessageConverter.writePart(FormHttpMessageConverter.java:422)
at org.springframework.http.converter.FormHttpMessageConverter.writeParts(FormHttpMessageConverter.java:393)
at org.springframework.http.converter.FormHttpMessageConverter.writeMultipart(FormHttpMessageConverter.java:373)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:277)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:95)
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:948)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:733)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:670)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:414)
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_FORM_URLENCODED));
headers.setAcceptCharset(Collections.singletonList(CharsetUtil.CHARSET_UTF_8));
FileSystemResource zipFile = new FileSystemResource(new File(file.getAbsolutePath()));
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
Long time = System.currentTimeMillis();
parts.add("time", time);
parts.add("md5", SecureUtil.md5(time + "234234").toUpperCase());
parts.add("file", zipFile);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(parts, headers);
什么HttpMessageConverter可以支持Long?
默认情况下,以下消息转换器在 spring 中启用:
ByteArrayHttpMessageConverter – converts byte arrays
StringHttpMessageConverter – converts Strings
ResourceHttpMessageConverter – converts org.springframework.core.io.Resource for any type of octet stream
SourceHttpMessageConverter – converts javax.xml.transform.Source
FormHttpMessageConverter – converts form data to/from a MultiValueMap<String, String>.
Jaxb2RootElementHttpMessageConverter – converts Java objects to/from XML (added only if JAXB2 is present on the classpath)
MappingJackson2HttpMessageConverter – converts JSON (added only if Jackson 2 is present on the classpath)
MappingJacksonHttpMessageConverter – converts JSON (added only if Jackson is present on the classpath)
AtomFeedHttpMessageConverter – converts Atom feeds (added only if Rome is present on the classpath)
RssChannelHttpMessageConverter – converts RSS feeds (added only if Rome is present on the classpath)
收到新请求时,Spring 将使用“接受”header 来确定响应with.In 您的情况所需的媒体类型,FormHttpMessageConverter
是spring中默认选择的转换器,因为您已经指定内容type.When写入多部分数据,此转换器使用其他HttpMessageConverters
写入相应的MIME部分。FormHttpMessageConverter
class 找不到 Long 类型的消息转换器。因此,您可以尝试将 Long 转换为字符串并将其分配给像 :
Long time = System.currentTimeMillis();
parts.add("time", String.valueOf(time));
parts.add("md5", SecureUtil.md5(time + "234234").toUpperCase());
parts.add("file", zipFile);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(parts, headers);