我有一个示例脚本:
var casper = require('casper').create();
var data, wsurl = 'http://api.github.com/users/mralexgray/repos';
casper.start('http://github.com/', function() {
data = this.evaluate(function(wsurl) {
return JSON.parse(__utils__.sendAJAX(wsurl, 'GET', null, false));
}, {wsurl: wsurl});
});
casper.then(function() {
require('utils').dump(data);
});
casper.run();
当我在我的控制台中运行时:
$ casperjs api.js --web-security=no
我得到了null
。为什么呢?
答案 0 :(得分:0)
Use https
on wsurl
,It worked for me.
var wsurl = 'https://api.github.com/users/mralexgray/repos';
casper.start('http://github.com/', function() {
data = this.evaluate(function(wsurl) {
try {
return JSON.parse(__utils__.sendAJAX(wsurl, 'GET', null, false));
} catch (e) {
__utils__.echo(e);
}
}, {wsurl: wsurl});
});