driverdan / node-XMLHttpRequest

XMLHttpRequest for node.js
http://thedanexperiment.com/2009/10/04/emulating-xmlhttprequest-in-node-js/
MIT License
416 stars 299 forks source link

FormData not supported! #174

Open vinitshahdeo opened 5 years ago

vinitshahdeo commented 5 years ago

xmlhttprequest throws an error while sending FormData object as an argument in send method.

var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
var FormData = require('form-data');

var data = new FormData();
data.append("foo", "\"baar\"");
data.append("lorem", "\"ipsum\"");

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
   if(this.readyState === 4) {
      console.log('******');
      console.log(JSON.parse(this.responseText));
   }
});

xhr.open("POST", "http://httpbin.org/post");
xhr.setRequestHeader("Content-Type", "text/plain");

xhr.send(data);

Running above code snippet throws the following error :

TypeError [ERR_INVALID_ARG_TYPE]: 
The "string" argument must be one of type string, Buffer, or ArrayBuffer. 
Received type object

@driverdan Please include the support for FormData.

Thanks:)