MSXML4 ServerXMLHTTP.4.0 encoding issue with responseText
Exchange Server Forum Index Exchange Server
Discussion forums for Microsoft Exchange Server users.
Microsoft Outlook
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web ExchangeServerHelp.com
MSXML4 ServerXMLHTTP.4.0 encoding issue with responseText

 
Post new topic   Reply to topic    Exchange Server Forum Index -> Development
Author Message
Guest






Posted: Fri Sep 30, 2005 11:01 pm    Post subject: MSXML4 ServerXMLHTTP.4.0 encoding issue with responseText Reply with quote

I'm using WebDAV to get message properties from MS Exchange server
(using ServerXMLHTTP object in MSXML, the sample code follows.)

If there are some non-ascii chars in message body, for example, 'ß',
the encoding of ServerXMLHTTP.4.0 responseText is incorrect (not in
Unicode, it just like double-byte UTF-8 chars): "C3 00" "9F
00".

However, if I use ServerXMLHTTP.3.0, XMLHTTP.4.0, or XMLHTTP.3.0, the
responseText are all in correct Unicode: "DF 00"

Is this a bug in MSXML4 ServerXMLHTTP.4.0 ? or some is there a
workaround?

Thanks!

'''''''''''''''''''' BEGIN OF SAMPLE CODE

sSourceUrl = "http://server/exchange/exadmin/Inbox/unicode.EML"

sXML = "<?xml version='1.0' encoding='utf-8' ?>"
sXML = sXML & "<d:propfind xmlns:d='DAV:'
xmlns:httpmail='urn:schemas:httpmail:' >"
sXML = sXML & "<d:prop><httpmail:textdescription/></d:prop>"
sXML = sXML & "</d:propfind>"
'WScript.echo "XML: [" & sXML & "]"

'Set xmlhttp = CreateObject("Msxml2.XMLHTTP.3.0")
'Set xmlhttp = CreateObject("Msxml2.XMLHTTP.4.0")
'Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.3.0")
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.4.0")
xmlhttp.open "PROPFIND", sSourceUrl, false, "domain\exadmin", "exadmin"
xmlhttp.setRequestHeader "Translate", "f"
xmlhttp.setRequestHeader "Content-type", "text/xml"
xmlhttp.setRequestHeader "Depth", "0"
xmlhttp.send(sXML)

' Return codes, etc.
if (xmlhttp.status > 299) Then
WScript.echo "Error " & xmlhttp.status & ": " & xmlhttp.responseText
end If

WScript.echo "HTTP response headers --> " &
xmlhttp.getAllResponseHeaders()
WScript.echo "XML returned --> " & xmlhttp.responseText

Set xmlhttp = nothing
Set adoStream = nothing

''''''''''''''''''''' END OF SAMPLE CODE

Back to top
Martin Honnen
Guest





Posted: Fri Sep 30, 2005 11:23 pm    Post subject: Re: MSXML4 ServerXMLHTTP.4.0 encoding issue with responseTex Reply with quote

wzhao2000@gmail.com wrote:


Quote:
If there are some non-ascii chars in message body, for example, 'ß',
the encoding of ServerXMLHTTP.4.0 responseText is incorrect (not in
Unicode, it just like double-byte UTF-8 chars): "C3 00" "9F
00".

But responseText is nothing that XMLHTTP _encodes_, instead it is a
string that XMLHTTP _decodes_ from the response body. The message body
does not contain any characters strictly, it is just a sequence of bytes
and you only get characters if you try to decode the byte sequence into
a sequence of characters.

Quote:
However, if I use ServerXMLHTTP.3.0, XMLHTTP.4.0, or XMLHTTP.3.0, the
responseText are all in correct Unicode: "DF 00"

WScript.echo "HTTP response headers --> " &
xmlhttp.getAllResponseHeaders()
WScript.echo "XML returned --> " & xmlhttp.responseText

So where do you check or try to check which bytes are in the response?
What exactly are the response headers? Do the response headers have a
Content-Type header, is a charset given in the headers?

And if you are looking for XML as that "XML returned" suggests why don't
you use responseXML then instead of responseText? responseXML and the
XML parser is much better at decoding than the simple approach
responseText takes.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Back to top
Guest






Posted: Sat Oct 01, 2005 12:58 am    Post subject: Re: MSXML4 ServerXMLHTTP.4.0 encoding issue with responseTex Reply with quote

forgot to mention how I checked returned char: if the char is correct,
it's displayed as " ß " in the WScript.Echo message box, otherwise
it's displayed as " ß "

Back to top
Guest






Posted: Sat Oct 01, 2005 12:58 am    Post subject: Re: MSXML4 ServerXMLHTTP.4.0 encoding issue with responseTex Reply with quote

Actually I'm using the responseXML property in real code to get the
node value of textdescription field. The issue is the same there: the
text is not in Unicode. (I used responseText in the sample is just for
illustration purpose.)

BTW, the content-type returned is "text/xml". Also, it works fine with
other objects, like ServerXMLHTTP.3.0, XMLHTTP.4.0, or XMLHTTP.3.0, ....
Back to top
Martin Honnen
Guest





Posted: Sat Oct 01, 2005 4:58 pm    Post subject: Re: MSXML4 ServerXMLHTTP.4.0 encoding issue with responseTex Reply with quote

wzhao2000@gmail.com wrote:

Quote:
forgot to mention how I checked returned char: if the char is correct,
it's displayed as " ß " in the WScript.Echo message box, otherwise
it's displayed as " ß "

I have created a test XML document that is UTF-16 encoded and uploaded
it here:
<http://home.arcor.de/martin.honnen/xml/test2005100101.xml>

Then I have written the following JScript program to be executed with
WSH (e.g. cscript):

function checkXml (url) {
var prefix = 'Msxml2';
var versions = [ '3.0', '4.0', '5.0', '6.0'];
var ids = ['XMLHTTP', 'ServerXMLHTTP'];
var result = [];
for (var i = 0; i < versions.length; i++) {
var version = versions[i];
for (var j = 0; j < ids.length; j++) {
var id = ids[j];
var programId = prefix + '.' + id + '.' + version;
result.push('Requesting ' + url + ' with ' + programId + ':');
try {
var httpRequest = new ActiveXObject(programId);
httpRequest.open('GET', url, false);
httpRequest.send(null);
result.push('HTTP status code: ' + httpRequest.status + ' ' +
httpRequest.statusText);
if (httpRequest.responseXML &&
httpRequest.responseXML.parseError.errorCode == 0) {
result.push('responseXML serialized:');
result.push(httpRequest.responseXML.xml);
}
}
catch (e) {
result.push('Error ' + e.message + ' with ' + programId);
}
result.push('\r\n');
}
}
return result.join('\r\n');
}

function main () {
for (var i = 0; i < WScript.Arguments.length; i++) {
WScript.Echo(checkXml(WScript.Arguments(i)));
}
}

main();

When I run that here from the command line as passing in the above URL
as an argument I get the following flawless results for MSXML 3, 4, 5, 6:

Requesting http://home.arcor.de/martin.honnen/xml/test2005100101.xml
with Msxml2.XMLHTTP.3.0:
HTTP status code: 200 OK
responseXML serialized:
<?xml version="1.0" encoding="UTF-16"?>
<root>
<text xml:lang="de">ß</text>
<text xml:lang="de">ä</text>
</root>



Requesting http://home.arcor.de/martin.honnen/xml/test2005100101.xml
with Msxml2.ServerXMLHTTP.3.0:
HTTP status code: 200 OK
responseXML serialized:
<?xml version="1.0" encoding="UTF-16"?>
<root>
<text xml:lang="de">ß</text>
<text xml:lang="de">ä</text>
</root>



Requesting http://home.arcor.de/martin.honnen/xml/test2005100101.xml
with Msxml2.XMLHTTP.4.0:
HTTP status code: 200 OK
responseXML serialized:
<?xml version="1.0" encoding="UTF-16"?>
<root>
<text xml:lang="de">ß</text>
<text xml:lang="de">ä</text>
</root>



Requesting http://home.arcor.de/martin.honnen/xml/test2005100101.xml
with Msxml2.ServerXMLHTTP.4.0:
HTTP status code: 200 OK
responseXML serialized:
<?xml version="1.0" encoding="UTF-16"?>
<root>
<text xml:lang="de">ß</text>
<text xml:lang="de">ä</text>
</root>



Requesting http://home.arcor.de/martin.honnen/xml/test2005100101.xml
with Msxml2.XMLHTTP.5.0:
HTTP status code: 200 OK
responseXML serialized:
<?xml version="1.0" encoding="UTF-16"?>
<root>
<text xml:lang="de">ß</text>
<text xml:lang="de">ä</text>
</root>



Requesting http://home.arcor.de/martin.honnen/xml/test2005100101.xml
with Msxml2.ServerXMLHTTP.5.0:
HTTP status code: 200 OK
responseXML serialized:
<?xml version="1.0" encoding="UTF-16"?>
<root>
<text xml:lang="de">ß</text>
<text xml:lang="de">ä</text>
</root>



Requesting http://home.arcor.de/martin.honnen/xml/test2005100101.xml
with Msxml2.XMLHTTP.6.0:
HTTP status code: 200 OK
responseXML serialized:
<?xml version="1.0" encoding="UTF-16"?>
<root>
<text xml:lang="de">ß</text>
<text xml:lang="de">ä</text>
</root>



Requesting http://home.arcor.de/martin.honnen/xml/test2005100101.xml
with Msxml2.ServerXMLHTTP.6.0:
HTTP status code: 200 OK
responseXML serialized:
<?xml version="1.0" encoding="UTF-16"?>
<root>
<text xml:lang="de">ß</text>
<text xml:lang="de">ä</text>
</root>



So at least with responseXML I can't reproduce any problem. Do you get
any different result for the sample XML document with your version of
MSXML 4?
If not can you post a URL to an XML document that causes the problem
with MSXML 4 ServerXMLHTTP?


Note the followup-to is set to microsoft.public.xml only.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Back to top
 
Post new topic   Reply to topic    Exchange Server Forum Index -> Development All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server Dedicated Servers
Contact Us
New Topics Powered by phpBB