Tech Off Post

Single Post Permalink

View Thread: Override XMLHTTPRequest charset
  • User profile image

    Sven Groot wrote:
    I'm requesting some text file using IE7's XMLHTTPRequest. XMLHTTPRequest is interpreting the file as utf-8, but it's not in fact that, and it breaks because of that. The server doesn't return a charset directive, and I have no control at all over the server.

    How can I make XMLHTTPRequest interpret the response with a different encoding? Or failing that, how can I manually decode the responseBody byte array into a string? Using nothing but javascript.

    An alternative method to download the file would also work. The script has local machine privileges so it can do more than a regular browser script.

    The default charset for XHR is UTF-8 with BOM being used to differentiate other encodings when the server returns no charset, so you might try using setRequestHeader() on the XHR to see if sending Accept-Charset might change the server's mind.

    Failing that, maybe this might help Wink