1.请求第三方接口,用feign请求
请求第三方接口,用feign请求,header不通,feign的写法不同
调用时报错Could not write request: no suitable HttpMessageConverter found for request type [com.ccreate.cnpc.mall.dto.zm.ZMPageQueryDTO] and content type [multipart/form-data;charset=UTF-8]
1. 对方接口是multipart/form-data接收格式
package com.mall.controller.feign;
import com.mall.controller.feign.fallback.ZMGoodFeignFallback;
import com.mall.dto.zm.ZMPageQueryDTO;
import com.mall.dto.zm.ZMSpuInfoDTO;
import com.ccreate.common.response.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* 商品
*/
@FeignClient(url = "${zm.host}", name = "cnpc-ZMGood", fallbackFactory = ZMGoodFeignFallback.class)
public interface ZMGoodFeign {
/**
* 商品列表查询
*
*/
@PostMapping(value = "/api/agent/goodsList", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
R<ZMSpuInfoDTO> getSpuList(@RequestBody ZMPageQueryDTO page);
}
对方返回的格式
{
code:200,
message:"ok",
data:{
list:[
{
id:"10001661",
name:"migo保温壶家用保温水壶大容量热水瓶304不锈钢热水壶保温瓶暖",
sellingPoint:"304不锈钢 坚韧把手 24小时长效保温",
skuType:"2",
brandId:"100094",
brandName:"miGo",
categoryId:"100

文章讲述了使用Feign客户端调用第三方接口时遇到的问题,涉及到`multipart/form-data`和`x-www-form-urlencoded`的不同接收格式,以及如何在SpringEncoder中适配不同内容类型。作者还提到将来可能需要处理header中的token信息。
最低0.47元/天 解锁文章
5627

被折叠的 条评论
为什么被折叠?



