'No HttpMessageConverter for [com.example.blog.SnapEngChatRequest] and content type [application/x-www-form-urlencoded]
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]
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!
Solution 1:[1]
I'm using spring boot here and I too get the same error what OP got here, the accepted solution didn't work out to me. At least tell me some ways so I can overcome this problem.
I tried the curl with content-type: application/x-www-form-urlencoded and it successfully gave me the response but the same when I try with sping boot I'm getting the error [ERROR] Exception while sending sms : No HttpMessageConverter for <<My_Class_Name>> and content type "application/x-www-form-urlencoded"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mannedear |
