Solved

MS ServerXMLHTTP or XMLHTTP Request

Posted on 2001-08-24
9
1,791 Views
Last Modified: 2007-11-27
I'm using MSXML2 HTTP Object and trying to post an XML to a URL, when I post I first convert XML into string and use URL encode method and finally call send method of the object. I have some spanish characters in the XML, but when I get the response back the spanish characters are not recognized and the system puts a ? mark where ever the spanish characters are present, this b'cos the response XML is always encoded in UTF-8 format and UTF-8 does not recognize spanish characters. Could anyone help me how to retrieve data in iso-8859-1 format when i use XML HTTP object.
0
Comment
Question by:dureddyvv
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 4

Accepted Solution

by:
edmund_mitchell earned 200 total points
ID: 6423101
That's the magic word ->

Strings are always encoded as UTF-16 on the Win32 platform.  You have no choice in this matter, you cannot change it.
From the horses' mouth:
 "Use strings when you want to display output, not when you're just shuttling it to the next piece of a processing pipeline."

~Andy Kimball
MSXSL Dev

Other gotchas:
1. loadXML() takes a UTF-16 string as an argument
2. responseText returns the response converted to a UTF-16 string
3. transformNode() returns a UTF-16 string
4. Response.Write() takes a UTF-16 string as an argument.  It then magically converts the string to a byte stream encoded using the current session codepage.

The solution is to rewrite your code to avoid caching intermediate output in string form.  Here is an example from some ASP I had to do battle with:

    // Get response object
    //
    // responseXML returns a document created by parsing
    //the response stream, so no need to call load
    var xmlResponseDoc = xmlPostObject.responseXML;

    // Create stylesheet object
    //
    var xslFile = "whatever.xsl";
    var xslDoc = new ActiveXObject("MSXML2.DOMDocument");
    xslDoc.async = 0;
    xslDoc.load(Server.MapPath(xslFile));

    // Apply stylesheet to xml
    //
    // Do not allow intermediate result to be cached in
    // a string.
    // Instead, output directly to the ASP response
    // stream in order to
    // preserve the requested encoding.
    xmlResponseDoc.transformNodeToObject(xslDoc, Response);

I also recommend setting Response.Charset = "8859-1" as well as Response.Content="text/html" so that the browser can be quickly informed of the content and encoding of the incoming page (this avoids auto-detection logic).

HTH

Edmund


0
 
LVL 10

Expert Comment

by:eyal_mt
ID: 6426344
make sure the you use the right codepage on the server - The first line should look some thing like this:

<%@ CODEPAGE=8859-1 Language=JavaScript %>

Then set the response charset:

Response.Charset = "8859-1"

And most important the header of your xml should include the encoding too, like this:

<?xml version='1.0' encoding='8859-1' ?>

good luck
0
 
LVL 10

Expert Comment

by:eyal_mt
ID: 6426350
0
 

Author Comment

by:dureddyvv
ID: 6426573
Thank you very much for your suggestions.
Well I'm not trying to display the return xml document to the browser.

Here is what exactly I have to do ..
I post a XML to a target url and i get a xml in response.
I have to save the response XML to a file and parse it to display only certain nodes/attributes.

Attached is the code I'm using to make a call and read the response...
Dim strResponseXML, xmlDoc, strXML
set xmldoc = Server.CreateObject("Msxml2.DOMDocument")

If xmldoc.loadXML(strXML) Then

     strResponseXML = mCallAllogis(xmldoc.xml)

End If
Function mCallAllogis(inXML)

Dim objinXMLdoc,objXMLHTTP, objResponsedoc
Dim strURL, strParameters, strinXML

set objinXMLdoc = Server.CreateObject("Msxml2.DOMDocument")
set objXMLHTTP     =
Server.CreateObject("Msxml2.ServerXMLHTTP")
set objResponsedoc = Server.CreateObject"Msxml2.DOMDocument")

strURL     = "http://localhost:81/http/postresponse.asp"
strParameters = "transactionName=processOrder&participant=Allogis&server=Allogis&message="

strinXML = strParameters + Server.URLEncode(strinXML)
objXMLHTTP.open "POST",strURL,False
objXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Response.ContentType = "application/xml"
Response.Charset = "1252"
objXMLHTTP.send strinXML

-- I HAVE TO READ THE RESPONSE HERE -----------....

End Function

The return XML is "iso-8859-1" encoded
As specified ealier , I have to read the XML in ASP and parse to extract only certain attributes/values and display them to the browser.
But when I read the Response the XML is not well formed do to special charcters.





0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6445586
FYI the MSXML2.ServerXMLHTTP object does not work on Win9x platforms, only Win2k/XP - the MSXML2.XMLHTTP object works on all of them, but is no good for server-class applications.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6785057
'test after sending
If objXMLHTTP.Status = 0 and objXMLHTTP.responseXML.parseError.errorCode = 0 Then
'to read the returned XML,
'first create the processing instruction with the appropriate encoding
oResult.appendChild oResult.createProcessingInstruction("xml","version='1.0' encoding='iso-8859-1'")
oResult.appendChild objXMLHTTP.documentElement
'now you have the correct syntax
End If

I had to do this for one project because using the responseText property caused the xml document to be either unloadable or the special accented characters were lost

Regards,

Brandon Driesen
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6789921
It's time to clean up this topic area and that means taking care of this question. Your options at this point are:

1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.

2. PAQ the question because the information might be useful to others, but was not useful to you. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

3.  Ask Community Support to help split points between participating experts.  Just comment here with details.

4.  Delete the question because it is of no value to you or to anyone else.  To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

If you elect for option 2, 3 or 4, just post comment with details here and I'll take it from there.  We also request that you review any other open questions you might have and update/close them.  Display all your question history from your Member Profile to view details.

PLEASE DO NOT AWARD THE POINTS TO ME.
____________________________________________
---------->  Hi Experts:

In the event that the Asker does not respond, I would very much appreciate your opinions as to which Expert ought to receive points (if any) as a result of this question.  Likewise, you can also suggest that I PAQ or delete the question.

------------->  The ALL TOPICS link has been updated today to reflect all the new TAs.

Thank you everyone.

Moondancer :)
Community Support Moderator @ Experts Exchange
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7067375
<recommendation>
points to edmund_mitchell
</recommendation>
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7067548
Thanks, b1xml2, for  your help here.

This has been finalized today, and monitoring for comments.

Moondancer - EE Moderator
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now