Discussion:
ServerXMLHttp responseXML is empty because of response's Content-T
(too old to reply)
d***@gmail.com
2006-07-02 02:40:45 UTC
Permalink
I am opening a GET request for an XML file on a remote server via a
proxy. I
cannot control the remote server. It is dynamically generating an XML
file
with Content-Type=text/html in the response header. How can I get
ServerXMLHttp to ignore that and think it is text/xml? I can't
setRequestHeader on a GET request, and as it is, responseXML returns
empty
and responseText has the space delimited data that I cannot easily
seperate
into nodes. What to do? Here is my code:

set xmlHttp = Server.CreateObject(""MSXML2.ServerXMLHTTP.4.0"")
xmlHttp.setProxy 2, ""http://virtualproxy.xxx.com:8080""
XML_path = ""http://news.xxx.com/xmlnewslink.cfm?vendorid=194&id="" &
ID
xmlHttp.open ""GET"", XML_path, False
xmlHttp.send
'at this point, it errs out due to an empty responseXML
set a_title =
xmlHttp.responseXML.selectSingleNode(""/NEWS_ITEM/NEWS_TITLE"")
set a_body =
xmlHttp.responseXML.selectSingleNode(""/NEWS_ITEM/NEWS_BODY"")

Note the culprit (I think) is a cold fusion page which generates the
XML
page, yet sets a content-type of text/html...how can I override
this?????
--
Joe Fawcett
2006-07-02 10:03:30 UTC
Permalink
Post by d***@gmail.com
I am opening a GET request for an XML file on a remote server via a
proxy. I
cannot control the remote server. It is dynamically generating an XML
file
with Content-Type=text/html in the response header. How can I get
ServerXMLHttp to ignore that and think it is text/xml? I can't
setRequestHeader on a GET request, and as it is, responseXML returns
empty
and responseText has the space delimited data that I cannot easily
seperate
set xmlHttp = Server.CreateObject(""MSXML2.ServerXMLHTTP.4.0"")
xmlHttp.setProxy 2, ""http://virtualproxy.xxx.com:8080""
XML_path = ""http://news.xxx.com/xmlnewslink.cfm?vendorid=194&id="" &
ID
xmlHttp.open ""GET"", XML_path, False
xmlHttp.send
'at this point, it errs out due to an empty responseXML
set a_title =
xmlHttp.responseXML.selectSingleNode(""/NEWS_ITEM/NEWS_TITLE"")
set a_body =
xmlHttp.responseXML.selectSingleNode(""/NEWS_ITEM/NEWS_BODY"")
Note the culprit (I think) is a cold fusion page which generates the
XML
page, yet sets a content-type of text/html...how can I override
this?????
--
When you say the text is space separated are you sure that's not just a
Unicode file misread by your editor?
Can you load the responseText into a DomDocument using loadXML?
--
Joe Fawcett - XML MVP


http://joe.fawcett.name
Martin Honnen
2006-07-02 13:31:07 UTC
Permalink
Post by d***@gmail.com
set xmlHttp = Server.CreateObject(""MSXML2.ServerXMLHTTP.4.0"")
xmlHttp.setProxy 2, ""http://virtualproxy.xxx.com:8080""
XML_path = ""http://news.xxx.com/xmlnewslink.cfm?vendorid=194&id="" &
ID
xmlHttp.open ""GET"", XML_path, False
xmlHttp.send
'at this point, it errs out due to an empty responseXML
First check what
xmlHttp.status
xmlHttp.statusText
and
xmlHttp.getAllResponseHeaders()
gives.

As you are only doing a HTTP GET request you could perhaps simply create
an MSXML DOM document and use its load method e.g.
Set xmlDocument = CreateObject("Msxml2.DOMDocument.4.0")
xmlDocument.setProperty "ServerHTTPRequest", True
xmlDocument.async = False
If xmlDocument.load(url) Then
' access node here
Else
' deal with xmlDocument.parseError here
End If

If that does not work (due to your need for special proxy settings) then
it might be possible to create an MSXML DOM document have it parse the
responseStream you get from the ServerXMLHTTP request so you could
continue to use your above code but after the send call you do e.g.
Set xmlDocument = CreateObject("Msxml2.DOMDocument.4.0")
xmlDocument.async = False
If xmlDocument.load(xmlHttp.responseStream) Then
' access node here
Else
' deal with xmlDocument.parseError here
End If

I would however include code after the send method that checks the HTTP
status you get.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Loading...