Set Accept-Language header

182 views
Skip to first unread message

Achmet Lahn

unread,
Nov 25, 2017, 3:24:52 PM11/25/17
to CasperJS
Hi guys,

I'm trying to set the Accept-Language header, but its not working for me.... :(

My code:

var casper =require('casper').create();
casper.start();

casper.on('started', function ()
{
    headers:
    {
        "Accept-Language": "de-CH"
    }
});

casper.thenOpen('http://casperjs.org', function() {
   
    this.echo(this.getHTML());
});

casper.run();

I'm using following versions:
Phantomjs: 2.1.1
Casperjs: 1.1.4

I'm getting this error:
SyntaxError: Unexpected token ':'

 phantomjs://code/branding.js:8 in injectJs

If I run the script with node:
 "Accept-Language": "de-CH"
                             ^
SyntaxError: Unexpected token :

When I add
method: 'get',
before 
"headers:"
            ^
 the error will be thrown at the headers colon.

The Doc for "header": http://docs.casperjs.org/en/latest/modules/casper.html#open

I've also tried (no errors given):
casper.page.customHeaders = {
        'Accept-Language': 'de-CH'
};

Also:
customHeaders:
{
      "Accept-Language": "de-CH"
}

And this:
var casper = require(‘casper’).create(
{
    pageSettings: {
        customHeaders: {
             "Accept-Language": "de-CH"
        }
    }
});
... also only with "header:"

I tried every snippet with this additional colon:
"Accept-Language:": "de-CH"
                          ^
 

But the result I scrape is always:
en,*
 
When browsing normal with latest Firefox, Chrome or Edge, everything is fine. This is the PHP Code:
<?php echo $_SERVER['HTTP_ACCEPT_LANGUAGE'];

I cant set any headers, but useragent. Any ideas?

Thanks
 

Ken Soh

unread,
Dec 10, 2017, 12:07:31 PM12/10/17
to CasperJS
Maybe this way to define the custom headers will work for you.. -

Reply all
Reply to author
Forward
0 new messages