本文介绍了自动重定向的特定网址的页面读取。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须阅读特定的网址并阅读该网页的内容,但会重定向到导致问题的其他网址。如何停止或读取我想要的网址。
我使用了以下方法来检索未能执行此操作的特定标记。
I have to read a specific url and read the contents of that page, but it redirects to other url which causes issue. How can i stop or read from the url i want.
I have used the follwing method to retrive specific tag which failed to do so.
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create("http://www.xxxxxxxx.aspx");
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
if (response1.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response1.GetResponseStream();
StreamReader readStream = null;
if (response1.CharacterSet == null)
{
readStream = new StreamReader(receiveStream);
}
else
{
readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response1.CharacterSet));
}
string data = readStream.ReadToEnd();
response1.Close();
readStream.Close();
}
推荐答案
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create("http://www.xxxxxxxx.aspx");
request1.AllowAutoRedirect = false;
...
这篇关于自动重定向的特定网址的页面读取。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!