提交 5c6b055e 编写于 作者: A Artem Zakharchenko 提交者: Jake Champion

Represent non-stringified JSON request body as an [object Object] string

上级 b5c8bd0f
......@@ -246,7 +246,9 @@ function Body() {
this._bodyText = body = Object.prototype.toString.call(body)
}
if (!this.headers.get('content-type')) {
const contentType = this.headers.get('content-type')
if (!contentType) {
if (typeof body === 'string') {
this.headers.set('content-type', 'text/plain;charset=UTF-8')
} else if (this._bodyBlob && this._bodyBlob.type) {
......@@ -254,6 +256,10 @@ function Body() {
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8')
}
} else if (contentType.includes('json') && typeof this._bodyInit !== 'string') {
// Always pass a text representation of a non-stringified JSON body
// to `XMLHttpRequest.send` to retain a compatible behavior with the browser.
this._bodyInit = this._bodyText
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册