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:
我已经创建了一个javascript库,我现在手动设置Content-Type。我很想知道什么是默认的Content-Type。 send()方法的XHR文档充其量令人困惑:
4. If body is null, go to the next step. Otherwise ...
4.如果body为null,请转到下一步。除此以外 ...
BodyInit
If body is a string, set encoding to
UTF-8
.如果body是字符串,请将编码设置为UTF-8。
Set request body and Content-Type to the result of extracting body.
将请求体和Content-Type设置为提取体的结果。
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).
那么,这些类型中的哪一种呢?传递给send()的主体采用默认的转义格式a = b&c = d。它是一个URLSearchParams?还是USVString?还是一个Blob?每个人都有一个描述,但对我来说太难以理解(我只知道它可能不是FormData)。
Note: please provide some official documentation if possible
注意:如果可能,请提供一些官方文档
1 个解决方案
#1
0
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.
直接来自马的嘴,如果你发送一个字符串,他们的最后一个测试需要“text / plain; charset = UTF-8”,符合XMLHttpRequest Level 1规范。
So you will have to refer to the step four of the send method to know exactly what is expected depending on the data.
因此,您必须参考send方法的第四步,以确切了解根据数据的预期结果。
#1
0
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.
直接来自马的嘴,如果你发送一个字符串,他们的最后一个测试需要“text / plain; charset = UTF-8”,符合XMLHttpRequest Level 1规范。
So you will have to refer to the step four of the send method to know exactly what is expected depending on the data.
因此,您必须参考send方法的第四步,以确切了解根据数据的预期结果。