PhantomJS onResourceError () 使用教程与错误信息解析


发布日期 : 2019-04-04 21:06:33 UTC

访问量: 10 次浏览

PhantomJS onResourceError()

当网页无法上传文件时,将调用此回调函数。它的参数是错误对象。

错误对象包含以下内容:

  • Id− 请求的编号。
  • URL− 调用的URL。
  • ErrorCode− 错误代码。
  • ErrorString− 错误详情。

语法

语法如下所示 −

wpage.onResourceError = function(resourceError) {}

示例

以下示例演示了 onResourceError() 方法的使用。

var wpage = require('webpage').create();
wpage.onResourceError = function(error) {
console.log(JSON.stringify(error));
}
wpage.open('http://localhost/tasks/prompt1.html', function(status) {
});

上述程序生成以下输出

{"errorCode":203,"errorString":"Error downloading http://localhost/tasks/prompt
.html - server replied: Not Found","id":1,"status":404,"statusText":"Not Found",
"url":"http://localhost/tasks/prompt1.html"}