Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a POST request in NightmareJs

I have been writing some test cases in PhantomJs and CasperJs. Recently I stumbled on NightmareJs which uses ElectronJs.

I wanted to know if I can automate POST requests (such as below) in NigthmareJs (maybe using goto, but I don't see any specifications for passing in params and changing the method):

PhantomJs code:

  page.open(url, 'post', params, function (status) {/*something*/});

And if so can I loop it a couple of times to monitor the time taken.

like image 913
zubair1024 Avatar asked Jul 06 '16 15:07

zubair1024


1 Answers

I think you are looking for node-rest-client

var Client = require('node-rest-client').Client;
var client = new Client();

  var args = {
    data: reqBody,
    headers: {
      "Content-Type": "application/json; charset=UTF-8"
    }
  };

  //console.log(args);
  var req = client.post("mypage/postResult", args, function(data, response) {
    console.log('Sent data: ', JSON.stringify(data, null, 2));
  });

  req.on('error', function(err) {
    console.log("Ouput posting failed due to error.", err);
  });
like image 117
devilpreet Avatar answered Sep 21 '22 05:09

devilpreet