-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unsupported BodyInit type when using fetch #6025
Comments
@peter0072000 please try |
@peter0072000 And make sure to specify the header type. Will look something like this...
|
Related #2538 |
Our server doesn't support plain/text media type in body. Tried to set 'Content-Type' header to 'application/json' also not working. How can i send request body in json? |
@xahon What do you mean? If your server does not support sending plain/text in the body it could mean it does not support sending POST methods which you need to send a body. If what you meant is that you cannot change the header I would just send all in one big string like so "{'text':'message'}". |
@sfratini means you are sending body as plain text - "{'text':'message'}" but we need to send as object like {'text':'message'} |
why do we need to convert json object to string in the post request? sorry, but it looks like sh*t and its really annoying when you have to do something like typeof options.body === 'string' ? options.body : JSON.stringify(options.body), |
Isn't the problem related to the answer and not the request? |
Totally agree with @oleksandrriabykh it became boring explaining backend guys that I'm limited to send them stringified body only. They were in disbelief when told them |
You can all install another fetch dependency and override the global.fetch. I am doing that right now in order to add a timeout to fetch and I am not having any of these issues. |
@sfratini I tried your solution with
and had no success. Is this the override you used? |
Hey,
When I using fetch to post a request on 0.20.0/0.19.0 version , it get 'unsupported BodyInit type' error:
following is request :
The text was updated successfully, but these errors were encountered: