- 全网能够搜索到的解决方式
- 原代码
package com.bp.feign;
import com.alibaba.fastjson.JSONObject;
import com.bp.entity.dpt.UnifiedDataReq;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(name = "unifiedData",url = "${unifiedDataService.newUrl}")
public interface UnifiedDataGatewayClient {
@PostMapping(value = "/organization/organizations/search")
JSONObject getDptData(@RequestBody UnifiedDataReq unifiedDataReq, @RequestHeader("Authorization") String accessToken, @RequestHeader("Content-Type") String contentType);
}
- 修改后的代码:
@PostMapping(value = “/organization/organizations/search”, consumes = “application/json”, produces = “application/json”)
代码语言:javascript复制package com.bp.feign;
import com.alibaba.fastjson.JSONObject;
import com.bp.entity.dpt.UnifiedDataReq;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(name = "unifiedData",url = "${unifiedDataService.newUrl}")
public interface UnifiedDataGatewayClient {
@PostMapping(value = "/organization/organizations/search", consumes = "application/json", produces = "application/json")
JSONObject getDptData(@RequestBody UnifiedDataReq unifiedDataReq, @RequestHeader("Authorization") String accessToken, @RequestHeader("Content-Type") String contentType);
}
- https://blog.csdn.net/qq_39107335/article/details/125887601?ops_request_misc=&request_id=&biz_id=102&utm_term=Invalid mime type “{Content-Ty&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-1-125887601.142v66control,201v3add_ask,213v2t3_esquery_v2&spm=1018.2226.3001.4187
- https://stackoverflow.com/questions/60798722/invalidmimetypeexception-invalid-mime-type-content-type-does-not-contain
- 如果这两个都解决不了;那可能跟我的问题有点相似
- 使用feign自定义拦截器
@Bean("requestInterceptor")
public RequestInterceptor requestInterceptor(){
return template -> {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if(attributes!=null){
HttpServletRequest request = attributes.getRequest();
if (null == request){
return;
}
log.info(request.getHeaderNames().toString());
template.header("token", request.getHeader("token"));
}else {
log.warn("requestInterceptor获取Header空指针异常");
}
};
}
- 解决前
- 解决后