Solved

MS ServerXMLHTTP or XMLHTTP Request

Posted on 2001-08-24
9
1,786 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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