How to make a POST request in NightmareJs
Asked Answered
G

1

8

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.

Ghostly answered 6/7, 2016 at 15:11 Comment(2)
github.com/segmentio/nightmare#gotourl-headersJudd
@ZoranPandovski that's not the questionTaylor
P
1

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);
  });
Pion answered 23/6, 2017 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.