1

I'm using Axios to POST to an external service where the URL requires including multiple apostrophes. The receiving service does not decode the URL of the received request, forcing us to figure out a way to POST to an unencoded URL.

I've not been able to discern any accessible way in which we could accomplish this.

const response = await axios.post("https://foo.bar/Company('ACME')", body, {
headers: {
      Authorization: this.authHeader,
      'Content-Type': 'application/json'
   }
})

The crux of the issue is having the URL include Company('ACME') without the apostrophes being URL-encoded to %27.

I've figured this to be possible with the native HTTPS module, but I'd like to see if this couldn't be accomplished with Axios (or a similar library).

const https = require('https');

const data = JSON.stringify({
    company: 'Acme Corporation'
});

const options = {
    "hostname": "foo.bar",
    "path": "/Company('ACME')",
    "method": "POST",
    "headers": {
        "Content-Type": "application/json",
        "Content-Length": data.length
    }
};


const req = https.request(options, (res) => {
    let data = '';

    console.log('Status Code:', res.statusCode);

    res.on('data', (chunk) => {
        data += chunk;
    });

    res.on('end', () => {
        console.log('Body: ', JSON.parse(data));
    });

}).on("error", (err) => {
    console.log("Error: ", err.message);
});

req.write(data);
req.end();

Is there any way to accomplish this with Axios or a similiar library?

Malmoc
  • 109
  • 1
  • 10
  • Possibly a duplicate https://stackoverflow.com/questions/39116731/how-to-prevent-axios-from-encoding-my-request-parameters – SmileIT Sep 15 '21 at 11:59
  • 1
    @SmileIT Thank you for pointing out that answer, although it's not so much any parameters I don't want encoded but the path. – Malmoc Sep 15 '21 at 12:08

0 Answers0