[com.example.blog.SnapEngChatRequest]和内容类型[application/x-www-form-urlencoded]没有HttpMessageConverter [英] No HttpMessageConverter for [com.example.blog.SnapEngChatRequest] and content type [application/x-www-form-urlencoded]
本文介绍了[com.example.blog.SnapEngChatRequest]和内容类型[application/x-www-form-urlencoded]没有HttpMessageConverter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用表单URL编码的标头调用post API.这是我的代码
I wanted to call a post API with form URL encoded header. Here's my code
var data = SnapEngChatRequest(
widgetId = widgetId,
visitorMessage = "Test"
)
val headers = HttpHeaders()
headers.set("x-api-key", apiKey)
headers.set("Content-Type", "application/x-www-form-urlencoded")
val entity = HttpEntity(data, headers)
val converter = FormHttpMessageConverter()
converter.supportedMediaTypes = singletonList(MediaType.APPLICATION_FORM_URLENCODED)
restTemplate.messageConverters.add(converter)
val result = restTemplate.exchange(
url,
HttpMethod.POST,
entity,
String::class.java
)
但是不幸的是,它无法正常工作,并且我遇到了错误
But unfortunately, it is not working and I'm getting below error
No HttpMessageConverter for [com.example.blog.SnapEngChatRequest] and content type [application/x-www-form-urlencoded]
org.springframework.web.client.RestClientException: No HttpMessageConverter for [com.example.blog.SnapEngChatRequest] and content type [application/x-www-form-urlencoded]
在这里,我正在提供httpMessageConverter,但是我不确定为什么它没有占用,或者我不确定在这里是否做错了什么.我已经尝试了所有可能的方法.任何帮助都会有所帮助,谢谢!
Here, I'm giving the httpMessageConverter but I'm not sure why it is not taking or I'm not sure if I'm doing something wrong here. I have tried everything possible. Any help will be helpful, Thanks!
推荐答案
查看全文