[英]How to make a POST request in NightmareJs
I have been writing some test cases in PhantomJs and CasperJs. 我已经在PhantomJ和CasperJ中编写了一些测试用例。 Recently I stumbled on NightmareJs which uses ElectronJs.
最近,我偶然发现了使用ElectronJs的NightmareJs。
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): 我想知道是否可以在NigthmareJs中自动执行POST请求(例如下面的请求)(也许使用goto,但是我看不到传递参数和更改方法的任何规范):
PhantomJs code: PhantomJs代码:
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 我认为您正在寻找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);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.