thanks for stopping by.
I want to send a new FormData()
as the body
of a POST
request using the fetch api
the operatio
fetch(url,options)
options.body
, you have to set the Content-Type
in request header ,or it will be text/plain
by default.If options.body is specific object like let a = new FormData()
or let b = new URLSearchParams()
, you don't have to set the Content-Type
by hand.It will be added automaticlly.
a
,it will be something likemultipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
as you see, the boundary is automaticlly added.
b
, it is application/x-www-form-urlencoded;