HttpRequest问题 [英] HttpRequest Question

查看:57
本文介绍了HttpRequest问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个快速而肮脏的小应用程序,它将转到一个网站

并刮取xml响应。


到目前为止它的工作正常,但有一个例外。 xml响应在顶部有一个xsl

样式表标签,这样当浏览器点击它时,xml就会转换为
。当我使用下面的代码时,我获得了

页面的转换版本而不是原始xml。任何人都可以告诉我如何获取我在IE中查看源代码时看到的原始xml

响应吗?


这是代码:


HttpWebRequest oRequest =(HttpWebRequest)

WebRequest.Create(" Http://www.randomwebsite.com/somexmlfile.xml");

HttpWebResponse oResponse =(HttpWebResponse)

oRequest.GetResponse();

Stream oStream = oResponse.GetResponseStream();

StreamReader oReader = new StreamReader(oStream);

Response.Write(oReader.ReadToEnd());

oResponse.Close();


谢谢!


Anthony

I''m working on a quick and dirty little app that will go out to a website
and scrape an xml response.

So far its working fine with one exception. The xml response has an xsl
stylesheet tag at the top so that when a browser hits it the xml is
transformed. When I use the code below I get the transformed version of the
page rather than the raw xml. Can anyone tell me how to get the raw xml
response that I see when I ''view source'' in IE?

Here is the code:

HttpWebRequest oRequest = (HttpWebRequest)
WebRequest.Create("Http://www.randomwebsite.com/somexmlfile.xml");
HttpWebResponse oResponse = (HttpWebResponse)
oRequest.GetResponse();
Stream oStream = oResponse.GetResponseStream();
StreamReader oReader = new StreamReader(oStream);
Response.Write(oReader.ReadToEnd());
oResponse.Close();

Thanks!

Anthony

推荐答案

如果使用会发生什么System.Net.WebClient改为?我不确定这是否会解决你的问题....


System.Net.WebClient web = new System.Net。 WebClient();


字符串数据= web.DownloadString(pageURL);

-

~~~~~~ ~~~~~

Ben Rush
http ://www.ben-rush.net/blog

" Anthony Sullivan" < an ***** @ anthonysullivan.netwrote in message

news:ED ************************* ********* @ microsof t.com ...
what happens if you use System.Net.WebClient instead? I''m not sure if this
will fix your problem or not....

System.Net.WebClient web = new System.Net.WebClient();

String data =web.DownloadString(pageURL);
--
~~~~~~~~~~~
Ben Rush
http://www.ben-rush.net/blog
"Anthony Sullivan" <an*****@anthonysullivan.netwrote in message
news:ED**********************************@microsof t.com...

我正在开发一个快速而又脏的小应用程序一个网站

并刮取xml响应。


到目前为止它的工作正常,有一个例外。 xml响应在顶部有一个xsl

样式表标签,这样当浏览器点击它时,xml就会转换为
。当我使用下面的代码时,我得到转换后的版本

页面而不是原始xml。谁能告诉我如何获得我在IE中查看源代码时看到的原始

xml响应?


这是代码:


HttpWebRequest oRequest =(HttpWebRequest)

WebRequest.Create(" Http://www.randomwebsite.com/somexmlfile.xml");

HttpWebResponse oResponse =(HttpWebResponse)

oRequest.GetResponse();

Stream oStream = oResponse.GetResponseStream();

StreamReader oReader = new StreamReader(oStream);

Response.Write(oReader.ReadToEnd());

oResponse.Close();


谢谢!


Anthony
I''m working on a quick and dirty little app that will go out to a website
and scrape an xml response.

So far its working fine with one exception. The xml response has an xsl
stylesheet tag at the top so that when a browser hits it the xml is
transformed. When I use the code below I get the transformed version of
the page rather than the raw xml. Can anyone tell me how to get the raw
xml response that I see when I ''view source'' in IE?

Here is the code:

HttpWebRequest oRequest = (HttpWebRequest)
WebRequest.Create("Http://www.randomwebsite.com/somexmlfile.xml");
HttpWebResponse oResponse = (HttpWebResponse)
oRequest.GetResponse();
Stream oStream = oResponse.GetResponseStream();
StreamReader oReader = new StreamReader(oStream);
Response.Write(oReader.ReadToEnd());
oResponse.Close();

Thanks!

Anthony



遗憾的是同样的事情。 :(


还有其他想法吗?


Ben Rush"< kw ***** @ yahoo.comwrote in message

新闻:ez ************** @ TK2MSFTNGP02.phx.gbl ...
Same thing unfortunately. :(

Any other ideas?

"Ben Rush" <kw*****@yahoo.comwrote in message
news:ez**************@TK2MSFTNGP02.phx.gbl...

what如果你使用System.Net.WebClient会发生吗?我不确定这个

是否会解决你的问题....


系统.Net.WebClient web = new System.Net.WebClient();


String data = web.DownloadString(pageURL);

-

~~~~~~~~~~~

Ben Rush
http://www.ben-rush.net/blog


" Anthony Sullivan" an *** **@anthonysullivan.net写信息

新闻:ED ******************************* *** @ microsof t.com ...
what happens if you use System.Net.WebClient instead? I''m not sure if this
will fix your problem or not....

System.Net.WebClient web = new System.Net.WebClient();

String data =web.DownloadString(pageURL);
--
~~~~~~~~~~~
Ben Rush
http://www.ben-rush.net/blog
"Anthony Sullivan" <an*****@anthonysullivan.netwrote in message
news:ED**********************************@microsof t.com...

>我正在开发一个快速而又脏的小应用程序,它将出现在一个网站上。 &>并刮取xml响应。

到目前为止它的工作原理没错,但有一个例外。 xml响应在顶部有一个xsl
样式表标记,这样当浏览器点击它时,xml就会被转换。当我使用下面的代码时,我得到了页面的转换版本,而不是原始的xml。谁能告诉我如何获得我在IE中查看源代码时看到的原始回复?

这是代码:

HttpWebRequest oRequest =(HttpWebRequest)
WebRequest.Create(" http://www.randomwebsite.com/somexmlfile.xml");
HttpWebResponse oResponse =(HttpWebResponse)
oRequest.GetResponse( );流oStream = oResponse.GetResponseStream();
StreamReader oReader = new StreamReader(oStream);
Response.Write(oReader.ReadToEnd());
oResponse.Close ();

谢谢!

Anthony
>I''m working on a quick and dirty little app that will go out to a website
and scrape an xml response.

So far its working fine with one exception. The xml response has an xsl
stylesheet tag at the top so that when a browser hits it the xml is
transformed. When I use the code below I get the transformed version of
the page rather than the raw xml. Can anyone tell me how to get the raw
xml response that I see when I ''view source'' in IE?

Here is the code:

HttpWebRequest oRequest = (HttpWebRequest)
WebRequest.Create("Http://www.randomwebsite.com/somexmlfile.xml");
HttpWebResponse oResponse = (HttpWebResponse)
oRequest.GetResponse();
Stream oStream = oResponse.GetResponseStream();
StreamReader oReader = new StreamReader(oStream);
Response.Write(oReader.ReadToEnd());
oResponse.Close();

Thanks!

Anthony



Do哟意味着你使用了查看源代码你看到转型内容了吗?否则

你必须压制样式表行。现在IMO你应该得到

XML文档,但是因为你还有嵌入其中的样式表引用,

你流式传输结果的浏览器仍将使用样式表。


否则我会试一试,但我怀疑WebRequest会自动处理

这个。另一种选择可能是服务器本身根据用户代理执行基于

的事情,如果它看起来已经转换了数据,那么就像用户代理不支持一样。样式表......

" Anthony Sullivan" < a ***** @anthonysullivan.netaécritdansle message de

news: ED ************************ **********@microsoft.com ...
Do yo meant you used "view source" and you see transformed content ? Else
you''ll have to suppress the stylesheet line. For now IMO you should get the
XML document but as you have still the stylesheet reference embedded in it,
the browser to which you stream the result will still use the stylesheet.

Else I''ll give this a try but I doubt WebRequest would automatically handle
this. Another option could be that the server itself does something based
for example on the user agent to render already transformed data if it looks
like the user agent doesn''t support stylesheets...
"Anthony Sullivan" <an*****@anthonysullivan.neta écrit dans le message de
news: ED**********************************@microsoft.com...

我正在研究一个快速而肮脏的小应用程序将去一个网站

并刮掉一个xml响应。


到目前为止它的工作正常,只有一个例外。 xml响应在顶部有一个xsl

样式表标签,这样当浏览器点击它时,xml就会转换为
。当我使用下面的代码时,我得到转换后的版本

页面而不是原始xml。谁能告诉我如何获得我在IE中查看源代码时看到的原始

xml响应?


这是代码:


HttpWebRequest oRequest =(HttpWebRequest)

WebRequest.Create(" Http://www.randomwebsite.com/somexmlfile.xml");

HttpWebResponse oResponse =(HttpWebResponse)

oRequest.GetResponse();

Stream oStream = oResponse.GetResponseStream();

StreamReader oReader = new StreamReader(oStream);

Response.Write(oReader.ReadToEnd());

oResponse.Close();


谢谢!


Anthony
I''m working on a quick and dirty little app that will go out to a website
and scrape an xml response.

So far its working fine with one exception. The xml response has an xsl
stylesheet tag at the top so that when a browser hits it the xml is
transformed. When I use the code below I get the transformed version of
the page rather than the raw xml. Can anyone tell me how to get the raw
xml response that I see when I ''view source'' in IE?

Here is the code:

HttpWebRequest oRequest = (HttpWebRequest)
WebRequest.Create("Http://www.randomwebsite.com/somexmlfile.xml");
HttpWebResponse oResponse = (HttpWebResponse)
oRequest.GetResponse();
Stream oStream = oResponse.GetResponseStream();
StreamReader oReader = new StreamReader(oStream);
Response.Write(oReader.ReadToEnd());
oResponse.Close();

Thanks!

Anthony



这篇关于HttpRequest问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆