【发布时间】:2017-08-28 23:42:38
【问题描述】:
我的 RESTful 服务允许 batching requests。
我正在尝试在Fetch API 的帮助下将请求合并为一批:
let req1 = {
url: "/cups/count",
options: {
method: 'GET',
headers: {
'Content-Type': 'application/http'
}
}
},
req2 = {
url: "/spoons/count",
options: {
method: 'GET',
headers: {
'Content-Type': 'application/http'
}
}
},
authToken = "Bearer my_token123",
batchUrl = "http://something.com/batch",
options = {
method: 'POST',
headers: {
'Authorization': authToken,
'Content-Type': 'multipart/mixed'
},
body: {req1, req2}
};
return fetch(batchUrl, options)
.then(response => response.json())
.then(items => dispatch(batchSuccess(items)))
.catch((err) => {
console.log(err)
});
但是它返回错误 - 错误请求。我想我可能会以错误的方式组合 HTTP 请求。
有没有更简单的方法?
我可以在网络 Chrome 开发工具的哪个位置看到嵌套的 HTTP 请求?
【问题讨论】:
标签: javascript http google-chrome-devtools fetch-api