Next.js Discord

Discord Forum

POST request fails to send body to backend API

Answered
Ichneumonid wasp posted this in #help-forum
Open in Discord
Avatar
Ichneumonid waspOP
My Next.js (with the app router) fails to send body data in a POST request back to my Express API. Postman is successfully able to submit data, but Next.js fails to pass data through. The screenshot is the API route that is being called-- you can see that data from my client form to the Next.js API is sent, but my backend fails to receive the data. Is there something wrong with my code (such as my headers) that prevents data from being passed through?
Image
Answered by Yi Lon Ma
set content type to application/json
View full answer

6 Replies

Avatar
set content type to application/json
Answer
Avatar
Ichneumonid waspOP
@Yi Lon Ma thanks! however I plan to send some base64 data through, hence why I utilized multipart/form-data. would that still be fine in an application/json setting?
Avatar
right now you're doing request.json() which returns a json string so you need application/json
Avatar
Ichneumonid waspOP
ohhhh
yeah that didn't click in my head. thanks for the help!
Avatar
np