XMLHTTP character issue - converting byte array to string

Discussion in 'ASP General' started by yllar2005@yahoo.com, Jan 31, 2006.

  1. Guest

    Hi!

    I'm using Msxml2.ServerXMLHTTP.3.0 to fetch a HTML page on a remote
    server. The fetched page is then parsed and the information of interest
    is extracted and send to the client browser.

    However, the remote server does not specify any character coding in its
    headers. If using ResponseText property in ServerXMLHTTP, some
    international characters are not decoded correctly. This is due to
    ResponseText assuming UTF-8 coding if no character set is specified.

    My solution is to use the ResponseBody property which returns the web
    page as an array of unsigned bytes. I then convert the data to a string
    using the ADODB.Stream method as described here:
    http://www.motobit.com/tips/detpg_binarytostring/

    The string is then parsed and the required information is pulled out.

    This solution works just fine but I wonder if there is some more
    efficient (without the need for a byte to string converion) way to
    solve the problem.

    BR,
    Yllar
     
    , Jan 31, 2006
    #1
    1. Advertising

  2. wrote:


    > This solution works just fine but I wonder if there is some more
    > efficient (without the need for a byte to string converion) way to
    > solve the problem.


    Well if you use the third method described on that URL then the
    ADODB.Stream object does all the work for you. The work itself (decoding
    the bytes into a text string) can't be avoided.

    --

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 31, 2006
    #2
    1. Advertising

  3. Have I understood this correctly, the remote server is sending
    international characters but not ones that are UTF-8 encoded and there is no
    charset in the headers? Have I got that right?

    Do you know the the implicit charset being set?

    If so then simply

    Set Response.CharSet = "whatever it is"
    Response.BinaryWrite oXMLHTTP.ResponseBody


    If not then you'll be asking the server to convert an unknown charset to a
    known one which isn't possible.

    Anthony.
     
    Anthony Jones, Jan 31, 2006
    #3
  4. Guest

    Yes, you got it right. If I request the server's content type by

    Response.Write objxmlhttp.GetResponseHeader("Content-Type")

    it will only return "text/html", hence no charset is sent.

    The web page I try to download contains Swedish characters (åäö) and
    I think that iso-8859-1 would work.

    I don't think that the solution you suggest will work in my case since
    I want to store the downloaded data in a variable and do some
    manipulation prior to displaying it. If ResponseBody is used, the data
    will be binary coded and text manipulation will not be possible.
     
    , Feb 12, 2006
    #4
  5. >I don't think that the solution you suggest will work in my case since
    >I want to store the downloaded data in a variable and do some
    >manipulation prior to displaying it. If ResponseBody is used, the data
    >will be binary coded and text manipulation will not be possible.


    Ok. Since you know the charset to be ISO-8859-1 then use Martin's
    suggestion.

    Anthony.
     
    Anthony Jones, Feb 14, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kirby
    Replies:
    3
    Views:
    653
    Kirby
    Oct 8, 2004
  2. cryptogirl
    Replies:
    5
    Views:
    24,853
    cryptogirl
    Feb 25, 2006
  3. Replies:
    1
    Views:
    390
    Lawrence Kirby
    Jul 6, 2005
  4. Polaris431
    Replies:
    8
    Views:
    762
    SM Ryan
    Dec 4, 2006
  5. yawnmoth

    Msxml*.XMLHTTP vs. Microsoft.XMLHTTP

    yawnmoth, Nov 7, 2006, in forum: Javascript
    Replies:
    11
    Views:
    400
    Matt Kruse
    Nov 9, 2006
Loading...

Share This Page