473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

XMLHTTP character issue - converting byte array to string

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 '06 #1
4 6090


yl*******@yahoo.com 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/
Jan 31 '06 #2
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.
Jan 31 '06 #3
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 '06 #4
>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.
Feb 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hari Prasad | last post by:
Hi, I am trying to convert a byte array to a string. I am using the possible ways but not getting the result. DatagramPacket dgram = new DatagramPacket(buf, buf.length); ByteArrayInputStream...
2
by: Uzi | last post by:
Hi! i have a memorystream object that has a byte array representing a sting. How do i tranform the byte array into a string. Thanks, Uzi
4
by: Prabhu | last post by:
Hi, We are having problem in converting a byte array to string, The byte array has char(174), char(175), char(240), char(242) and char(247) as delimiters for the message. when we use...
1
by: Nadav | last post by:
Hi, I wonder... is it possible to convert a 'byte' array to a string? ( cocerning the byte array was initialized using System.String.ToCharArray() ) -- Nadav http://www.ddevel.com
1
by: Benoit | last post by:
Hi, what is the most performing way to convert a byte stream to a string? Byte() to be converted to String. Thanks, iBen. Sorry if it ia a double post in this newsgroup, I cannot set my...
8
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
3
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hello, I've eliminated the bulk of code, this should be sufficient: byte fromEncrypt; string sDecryptedString; //Read the data out of the crypto stream. csDecrypt.Read(fromEncrypt, 0,...
4
by: arunfr | last post by:
Hi , I have tried all the methods available to convert byte () to string and vice versa in VBSCRIPT. Function ByteArray2Text(varByteArray) Dim rs Const adLongVarChar = 201 Set rs =...
5
jeffbroodwar
by: jeffbroodwar | last post by:
Hi everyone, I have a program that converts variables long,string,double to byte array here's the code : for long : //CompanyId temp = longToByteArray(CompanyId); ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.