【发布时间】:2019-12-22 22:08:51
【问题描述】:
我正在尝试使用 fetch API 将 XML 字符串而不是 JSON 对象发布到 node.js 服务器。
这是我发布 JSON 对象的代码:
handleSubmit = async e => {
e.preventDefault();
var request = JSON.stringify({
drug: this.state.drug,
disease: this.state.disease,
type: this.state.type
});
var xmlRequest = js2xmlparser.parse("request", request);
const response = await fetch('/api/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: request
});
const body = await response.text();
this.setState({
responseToPost: body
});
}
如何编辑代码以在请求正文中发布 XML 字符串(xmlRequest)而不是 JSON(请求)。
【问题讨论】:
标签: node.js xml fetch fetch-api