Is there a shorthand to get the contents of an htt...
# ktor
h
Is there a shorthand to get the contents of an http POST operation in a map? I use the same procedure as the example linked from http://ktor.io/samples/post.html, but find it unneccessary to iterate over a MultipartData structure to get my values. Changing the content type from form-data to x-www-form-urlencoded doesn't help, I still don't find a simple
toMap()
. Am I missing something?
c
Use
call.receive<StringValues>()
There is no reason to use multipart unless you need to create a file upload form
We need to complete this example to cover both cases
h
OK, trying. And I'm sorry for asking this, (but I remember now why I didn't go that way in the first place): why do I then get a 415 Unsupported Media Type: POST?
My HTML is pretty simple: <form action="/test" method="post"> <p>To: <input type="text" name="to" value=""></p> <p>Heading: <input type="text" name="heading"></p> <p>Summary: <input type="text" name="summary"></p> <p><input type="checkbox" name="recommend"> Also create a recommendation</p> <p><input type="submit" name="submit"></p> </form>
Did I miss a setting permitting POST somewhere?
The 415 comes when I use a ContentNegotiation with jackson ... If I comment that part out, I get a regular 500 error: ContentTransformationException: Cannot transform this request's content to class io.ktor.util.StringValues ...
o
receiveParameters
should work
h
Yes it did. Thanks, @cy and @orangy!
Funny: with
install(ContentNegotiation)
, I got a 415. Without it, I got a 500. But since it now works fine with
receiveParameters
, I'm not looking backwards. I do look forward to seeing more documentation, though...
o
@Deactivated User is working on docs! Hurray 🙂
d
🙂 Yep. Thanks for the feedback @hallvard ! I’m taking notes about this and will update documentation accordingly