I am trying to post XML string instead of JSON object to node.js server using fetch API.
This is my code which post JSON object:
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
});
}
How to edit the code to post XML string(xmlRequest) instead of JSON (request) in the request body.