标签搜索

目 录CONTENT

文章目录

Invalid mime type \"application-json; charset=utf-8;charset=ISO-8859-1\": does not contain '/'

高大北
2022-11-28 / 0 评论 / 0 点赞 / 150 阅读 / 340 字 / 正在检测是否收录...
  • 全网能够搜索到的解决方式
  • 原代码
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”)

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);
}
    @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空指针异常");
            }
        };
    }
  • 解决前

  • 解决后

0

评论区