How to get body of a POST request

I am using Worker as a webhook URL to pull the data. The request made by the invoked entity is using POST and application/x-www-form-urlencoded. Since it seems to be unable to be logged in the result due to content type, how do I get the data or log them in Worker?
2 Replies
DaniFoldi
DaniFoldi5mo ago
Here's a quick snippet that should work, although I have not tested this much and I recommend looking at hono if they have a better implementation:
const text = await request.text()
const entries = text.split('&').map(x => x.split('=').map(decodeURIComponent))
const body = Object.fromEntries(entries)
const text = await request.text()
const entries = text.split('&').map(x => x.split('=').map(decodeURIComponent))
const body = Object.fromEntries(entries)
ianyen
ianyen5mo ago
I solved it by using formData() but I will test your solution and see how it goes. Thanks for the help!
Want results from more Discord servers?
Add your server