[英]HtmlAgilityPack - How to get url path after redirect
I'm trying to get a Url full path after it's doing redirect, simply here is the code:我正在尝试在进行重定向后获得 Url 完整路径,这里是代码:
var documentx = new HtmlWeb().Load(textBox1.Text);
Where the textbox1.text value is " https://xxxx.org/file/download "其中textbox1.text值为“ https://xxxx.org/file/download ”
so after i run that code in real it's redirect and change the structure to:所以在我真正运行该代码后,它会重定向并将结构更改为:
https://xxxx.org/file/ur344333kd/45rrreew
so how i can get the new url path?那么我怎样才能获得新的 url 路径? using HtmlAgilityPack C# Winform .使用HtmlAgilityPack C# Winform 。 Thanks谢谢
By setting web.CaptureRedirect
to true, and by querying web.ResponseUri
,通过将web.CaptureRedirect
设置为 true,并通过查询web.ResponseUri
,
You can get the Url of the final request which actually downloaded the document:您可以获取实际下载文档的最终请求的 Url:
Note: I am sending this UserAgent string, just like my Chrome Browser because server behavior may change depending on it.注意:我发送这个 UserAgent 字符串,就像我的 Chrome 浏览器一样,因为服务器行为可能会根据它而改变。
HtmlWeb web = new HtmlWeb();
web.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36";
web.CaptureRedirect = true;
HtmlDocument doc = web.Load("http://www.google.com");
Console.WriteLine("Response retrieved from: {0}", web.ResponseUri);
The output is: output 是:
Response retrieved from: https://www.google.com/?gws_rd=ssl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.