views:

148

answers:

2

I'm using the HttpWebRequest object to make a get call to a site/web service that uses XML/XSLT as its front end. When I view the source in Firefox the XML comes up, but when I make the request in my program the transformed document is returned to me.

As the transformed document is very useless to me, how can I make the request and get the straight XML back?

A: 

Not a problem on my end. Basically, the host that I'm requesting from requires a real browser's UserAgent in order for the xml to come back. Seems to me like it would be better left for ContentType or Accepts header fields, but whatever.

Wes P
A: 

当我使用HTTPWebRequest或者WebClient时,也发生与你同样的问题。 使用下面的代码可以获取到XML数据(需要引用Microsoft XML COM组件): string result = string.Empty; string url = string.Format("http://xxx/Sub:{0}", searchWord); MSXML2.ServerXMLHTTP _xmlhttp = new MSXML2.ServerXMLHTTP(); _xmlhttp.open("GET", url, false, null, null); _xmlhttp.send(string.Empty); if (_xmlhttp.readyState == 4) { result = System.Text.Encoding.GetEncoding("utf-8").GetString((byte[])_xmlhttp.responseBody); }

Log.Debug(result);

Hsqzzzl