When using the JS console in the latest version of Chrome browser, I encountered the following issue:
x = new XMLHttpRequest();
x.open('POST', '?a=2');
x.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded; charset="ISO-8859-1"');
x.send({b:2});
An error occurred where the request was sent with the incorrect encoding. Upon inspecting the network, I noticed:
Content-Type:application/x-www-form-urlencoded; charset="UTF-8"
Additionally, there was a strange behavior observed when specifying charset=ISO-8859-1
instead of charset="ISO-8859-1"
, as it resulted in:
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Clearly indicating a change had occurred.
Edit 2013/12/11
Interestingly, the bug that stood out to me was that if no data is sent, the encoding change functions correctly. Consider this revised example (noting the adjustment on the last line) :
x = new XMLHttpRequest();
x.open('POST', '?a=2');
x.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded; charset="ISO-8859-1"');
x.send();
In this scenario, the network output correctly displays:
Content-Type:application/x-www-form-urlencoded; charset="ISO-8859-1"
Quite puzzling indeed...