Unable to load url json with Casper Js - & gt; & Ldquo; Loading the failed resource with status = fail & rdquo;

advertisements

I am new to casper js and I would like to retrieve a json object from a get request. The message I get is the following :

Loading resource failed with status=fail: https://api.twitter.com/1.1/search/tweets.json?q=casperjs

Here is my code :

var casper = require('casper').create({
  verbose: true,
  logLevel: 'debug',
  pageSettings: {
    loadImages: false,
    loadPlugins: false,
    userAgent: 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36'
  }
});

casper.start().then(function() {
    this.open('https://api.twitter.com/1.1/search/tweets.json?q=casperjs', {
        method: 'get',
        headers: {
            'Accept': 'application/json'
        }
    });
});

casper.then(function() {
    require('utils').dump(JSON.parse(this.getPageContent()));
});

casper.run(function() {
    this.exit();
});

I have spent lot of time to understand what was going wrong without any succeed. I have not find other similar problems on stack... meaning I must do something wrong.

Thank you for your help

my configuration (from brew info):

  • casperjs: stable 1.0.4 (bottled), devel 1.1-beta3, HEAD
  • phantomjs: stable 2.0.0 (bottled), HEAD

As suggested by @Artjom B., I used the following command line option --ignore-ssl-errors=trueand the file suceeded in loading the json.