0
votes

I'm trying to send a post xml request, but the body of the request is empty. using bodyParser I managed to transform the content type. But the backend expects a content-type: "text/xml" and in my request content-type: "application/x-www-form-urlencoded", even passing content-type: "text/xml". It's giving error 415.

How to send the body of the request with the text/xml type?

my bodyParser declaration:

const bodyParser = require("body-parser");
app.use(bodyParser.text({ type: "text/xml" }));
1
Please share the code that creates the POST request. Is it Javascript code, or just an HTML form? - Heiko Theißen

1 Answers

0
votes

Keeping in mind that the text body parser will parse your request as plain text and not as XML, so you will need to do XML parsing as a separate step.

To set the content type of the request using axios:

const xml = "<example><childNode /></example>";
axios({
    method: 'post',
    url: '/example',
    headers: { 
        'content-type': 'text/xml' 
    },
    data: xml,
});