Ardor API: Not able to use POST requests with Axios due to CORS issuessteemCreated with Sketch.

in #news6 years ago

I am having issues with POST requests to the Ardor API. This code:

<!DOCTYPE html>
<html>
<head>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  <script>
  function myFunction() {
      let nodeurl = "https://testardor.jelurida.com/nxt";
      const query = {
        recipient:'ARDOR-KZ3Y-4B97-6KF6-2V8WA',
        amountNQT:34,
        feeNQT:-1,
        deadline:15
      };
      axios.post(nodeurl, query)
      .then(function(response) {
        console.log(response.data);
        document.getElementById("demo").innerHTML = response.data;
      })
      .catch(function (error) {
        console.log(error.message);
      });
  }
  </script>
</head>

<body>

<h2>Preflight request to CORS enabled Ardor Node fails</h2>

<p id="demo">The result should appear here</p>
<button type="button" onclick="myFunction()">Try it</button>
</body>
</html>

fails during preflight. Chrome:

Failed to load http://localhost:26876/nxt: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:3000' is therefore not allowed access. The response had HTTP status code 403.

What I understand is that it is not me who needs to send the 'Access-Control-Allow-Origin' header but the Ardor/NXT node.

Likely its just me not getting it. There are options around, you can change the content type, is that possible with NXT API? Is that something anybody had to do?

Its just failing for POST, GET works fine.

Thanks for any pointers in the right direction.

Sort:  

This user is on the @buildawhale blacklist for one or more of the following reasons:

  • Spam
  • Plagiarism
  • Scam or Fraud

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 62892.68
ETH 2581.23
USDT 1.00
SBD 2.73