提交 f36e9e40 编写于 作者: D David Graham

Remove form encoded object body.

This was based on a misreading of the URLSearchParams portion of
section 5.2 of https://fetch.spec.whatwg.org/#body-mixin.

Use FormData as the request body to POST form fields instead.
上级 fc28061b
......@@ -102,18 +102,6 @@ fetch('/query', {
})
```
### Post form fields
```javascript
fetch('/query', {
method: 'post',
body: {
name: 'Hubot',
login: 'hubot'
}
})
```
### Post JSON
```javascript
......
......@@ -120,15 +120,6 @@
this.referrer = null
}
function encode(params) {
return Object.getOwnPropertyNames(params).filter(function(name) {
return params[name] !== undefined
}).map(function(name) {
var value = (params[name] === null) ? '' : params[name]
return encodeURIComponent(name) + '=' + encodeURIComponent(value)
}).join('&').replace(/%20/g, '+')
}
function decode(body) {
var form = new FormData()
body.trim().split('&').forEach(function(bytes) {
......@@ -142,15 +133,6 @@
return form
}
function isObject(value) {
try {
return Object.getPrototypeOf(value) === Object.prototype
} catch (ex) {
// Probably a string literal.
return false
}
}
function headers(xhr) {
var head = new Headers()
var pairs = xhr.getAllResponseHeaders().trim().split('\n')
......@@ -190,12 +172,7 @@
})
})
var body = self.body
if (isObject(self.body)) {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
body = encode(self.body)
}
xhr.send(body)
xhr.send(self.body)
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册