2016-07-06 52 views
8

Ho scritto alcuni casi di test in PhantomJs e CasperJs. Recentemente sono incappato in NightmareJs che usa ElectronJs.Come effettuare una richiesta POST in NightmareJs

volevo sapere se posso automatizzare le richieste POST (come di seguito) in NigthmareJs (magari usando goto, ma non vedo alcuna specifica per il passaggio in params e cambiare il metodo): Codice

PhantomJs :

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

E in tal caso, posso farlo un paio di volte per monitorare il tempo impiegato.

+0

https://github.com/segmentio/nightmare#gotourl-headers –

+0

@ZoranPandovski che non è la questione – ospider

risposta

1

Penso che si sta cercando 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); 
    });