简体   繁体   中英

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.

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);
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM