PhantomJS onResourceTimeout()
当请求的资源超时时,将调用此回调函数。也就是当使用settings.resourceTimeout回调函数时。
它包含一个参数,即 request 它具有以下详细信息−
- Id − 请求资源的编号
-
Method − HTTP方法
-
URL − 请求资源的URL
-
Time − 包含请求日期的日期对象
-
Headers − HTTP头列表
-
ErrorCode − 错误的错误代码
-
ErrorString − 错误的文本消息
语法
其语法如下−
page.onResourceTimeout = function(request) {}
示例
var wpage = require('webpage').create();
wpage.onResourceTimeout = function(request) {
console.log("Data from request:");
console.log(JSON.stringify(request));
}
wpage.settings.resourceTimeout = '3';
wpage.open('http://localhost/tasks/request.html', function(status) {
});
上面的程序生成以下 输出 。
Data from request:
{"errorCode":408,"errorString":"Network timeout onresource.",
"headers":[{"name":"Accept","value":"text/html,application/xhtml+xml ,
application/xml;q=0.9,*/*;q=0.8"},{"name":"User-Agent","value":"Mozilla/5.0
(Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko)
PhantomJS/2.1.1 Safari/538.1"}],"id":1,
"method":"GET","time":"2017-0507T13:32:12.545Z",
"url":"http://localhost/tasks/request.html"
}