how can i write the javascript equivalent for curl code?

I took your curl command and put it into this website: https://reqbin.com/req/c-w7oitglz/convert-curl-to-http-request

You can change the url from google to your localhost

var url = "https://google.com";

var xhr = new XMLHttpRequest();
xhr.open("POST", url);

xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
      console.log(xhr.status);
      console.log(xhr.responseText);
   }};

var data = "dataRequest=demo1";

xhr.send(data);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top