ajax post - I want to change the Accept-Encoding header value ajax post - I want to change the Accept-Encoding header value ajax ajax

ajax post - I want to change the Accept-Encoding header value


This value is probably being overwritten later in the process.

Ref: http://api.jquery.com/jQuery.ajax/
headers (default: {}) description
Type: PlainObject
An object of additional header key/value pairs to send along with the request. This setting is set before the beforeSend function is called; therefore, any values in the headers setting can be overwritten from within the beforeSend function.

Try implementing beforeSend as seen in the demo code below and the header value(s) should get to the final request now (fingers crossed).

var ajaxParams = {    accepts: 'text/html',    async: true,    cache: false,    contentType: 'text/html',    url: 'http://www.google.com',    type: 'GET',    beforeSend: function (jqXHR) {        // set request headers here rather than in the ajax 'headers' object        jqXHR.setRequestHeader('Accept-Encoding', 'deflate');    },    success: function (data, textStatus, jqXHR) {        console.log('Yay!');    },    error: function (jqXHR, textStatus, errorThrown) {        console.log('Oh no!');    },    complete: function (jqXHR, textStatus) {        console.log(textStatus);        console.log(jqXHR.status);        console.log(jqXHR.responseText);    }};$.ajax(ajaxParams);


This is not possible because of choosing the right encoding type by browser. If you do this

var ajaxParams = {accepts: 'text/html',async: true,cache: false,contentType: 'text/html',url: 'http://www.google.com',type: 'GET',beforeSend: function (jqXHR) {    // set request headers here rather than in the ajax 'headers' object    jqXHR.setRequestHeader('Accept-Encoding', 'deflate');},......

You'll see this error:

Refused to set unsafe header "Accept-Encoding"

Ref: App Engine Accept-Encoding


I'm not sure that 'none' is a valid option there. I believe if you set the headers to accept encoding 'deflate' rather than 'none', that should sort out your problem.

e.g.

headers: { 'Accept-Encoding' : 'deflate' }