feign icon indicating copy to clipboard operation
feign copied to clipboard

Content type 'application/octet-stream' not supported

Open zza1998 opened this issue 2 years ago • 1 comments

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:225) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:158) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:131) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-5.2.8.RELEASE.jar!/:5.2.8.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:167) ~[spring-web-5.2.8.RELEASE.jar!/:5.2.8.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134) ~[spring-web-5.2.8.RELEASE.jar!/:5.2.8.RELEASE] atorg.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]

when I use openFeign to request one springboot service from another one , The above error occurred。 I find some data about. the only thing I can confrim is that the request header 'content-type' is lost. but i dont konw why and how to fix it. because test env is ok. but product env is just always wrong. following is all code about feign

         <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
             <version>2.2.5.VERSION<version>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-httpclient</artifactId>
            <version>10.10.1</version>
        </dependency>
@Configuration
@Slf4j
public class FeignConfig  {

    @Bean
    public RequestInterceptor requestInterceptor() {
        return template -> {
            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
                    .getRequestAttributes();
            if (null != attributes) {
                HttpServletRequest request = attributes.getRequest();
                // 获取原请求头参数
                Enumeration<String> headerNames = request.getHeaderNames();
                if (headerNames != null) {
                    while (headerNames.hasMoreElements()) {
                        String name = headerNames.nextElement();
                        String values = request.getHeader(name);
                        // 传入本次feign调用模板中
//                          if (!name.equals("token")) continue;
                        template.header(name, values);
                    }
                }
            }
}
@FeignClient(contextId = "xxxx",name = "xxxxx")
public interface CCCFeignClient {
    @PostMapping(value = "/ccc/subscribe")
    CommonRes<SubscribeRes> subscribe(SubscribeReq subscribeReq);
}

zza1998 avatar Oct 19 '21 02:10 zza1998

You can set the @PostMapping consumes paramter as 'application/octet-stream'.

mroccyen avatar Mar 04 '22 03:03 mroccyen