Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content type 'application/octet-stream' not supported #1522

Open
zza1998 opened this issue Oct 19, 2021 · 1 comment
Open

Content type 'application/octet-stream' not supported #1522

zza1998 opened this issue Oct 19, 2021 · 1 comment

Comments

@zza1998
Copy link

zza1998 commented Oct 19, 2021

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);
}
@mroccyen
Copy link
Contributor

mroccyen commented Mar 4, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants