fetch - Missing boundary in multipart/form-data POST

前端 未结 6 1562
不知归路
不知归路 2020-11-27 14:45

thanks for stopping by.

I want to send a new FormData() as the body of a POST request using the fetch api

the operatio

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 15:11

    fetch(url,options)
    
    1. If you set a string as options.body, you have to set the Content-Type in request header ,or it will be text/plain by default.
    2. 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.

      • for a ,it will be something like

      multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

      as you see, the boundary is automaticlly added.

      • for b, it is application/x-www-form-urlencoded;

提交回复
热议问题