我正在尝试使用应用程序/x-www-form-urlencoded发出API请求。
这是我的假客户端:
@Bean
public YandexDelivery yandexDelivery() {
return Feign.builder()
.client(new OkHttpClient())
.encoder(new FormEncoder())
.decoder(new GsonDecoder())
.logger(new Slf4jLogger(YandexDelivery.class))
.logLevel(Logger.Level.FULL)
.target(YandexDelivery.class, "https://delivery.yandex.ru/api/last/searchDeliveryList");
}
这是我的界面:
public interface YandexDelivery {
@RequestLine("POST")
@Headers({"Content-Type: application/x-www-form-urlencoded"})
Delivery getDeliveryVariants(Map<String, ?> request);
}
这就是我所说的:
@Autowired
private YandexDelivery yandexDelivery;
@Override
public Delivery getDeliverysType(String cityFrom, String cityTo, Integer clientId, String deliveryType, Integer height, Integer indexCity, Integer length, Integer senderId, Integer weight, Integer width) {
DeliveryVariantsModel model = new DeliveryVariantsModel(cityFrom, cityTo, clientId, deliveryType, height, indexCity, length, senderId, weight, width);
HashMap<String, String> map = new HashMap<>();
map.put("secret_key", model.getSecretKey());
map.put("client_id", model.getClientId().toString());
map.put("sender_id", model.getSenderId().toString());
map.put("city_from", model.getCityFrom());
map.put("city_to", model.getCityTo());
map.put("weight", model.getWeight().toString());
map.put("length", model.getLength().toString());
map.put("width", model.getWidth().toString());
map.put("height", model.getHeight().toString());
map.put("delivery_type", model.getDeliveryType());
map.put("index_city", model.getIndexCity().toString());
return yandexDelivery.getDeliveryVariants(map);
}
这是我的错误:
java.lang.ClassNotFoundException: feign.Request$Body
您是否遗漏了
依赖项中的spring-cloud-starter-feign
?
我遇到了同样的问题。修复是将正确的 Spring 云依赖项安装到使用的 Spring 引导版本。您可以在 https://start.spring.io/actuator/info 中找到正确的设置在我的 Spring Boot 版本 2.1.2.RELEASE 的情况下,我不得不使用 spring-cloud.version Greenwich.SR1