简体   繁体   中英

What is the default Content-Type in XMLHttpRequest?

I have created a javascript library and I am setting manually the Content-Type right now. I would love to know what is the default Content-Type . The XHR documentation for the send() method is confusing at best:

4. If body is null, go to the next step. Otherwise ...

BodyInit

If body is a string, set encoding to UTF-8 .

Set request body and Content-Type to the result of extracting body.

Where, the result of extracting body for a text is:

  • Blob
  • BufferSource
  • FormData
  • URLSearchParams
  • USVString

So, which of these types would it be? The body passed to send() is in the default, escaped format of a=b&c=d . Is it a URLSearchParams ? or a USVString ? or a Blob ? There's a description on each one but it's too cryptic for me to understand (I only know that it's probably not a FormData ).

Note: please provide some official documentation if possible

Directly from the horse's mouth , if you are sending a string their last test expects "text/plain;charset=UTF-8" in accordance with the XMLHttpRequest Level 1 specification .

So you will have to refer to the step four of the send method to know exactly what is expected depending on the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM