As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center作为指导。
7年前关闭。
我有一个文本文件,列出了超过250,000个网站URL。遍历每个URL,如果它将我重定向到特定URL(不同的站点),我想将其保存到另一个文本文件。
我是C#开发人员,我知道如何读写文件和小片段,但是正在寻找最好的逻辑或方法以任何编程语言来完成上述任务和脚本。
7年前关闭。
我有一个文本文件,列出了超过250,000个网站URL。遍历每个URL,如果它将我重定向到特定URL(不同的站点),我想将其保存到另一个文本文件。
我是C#开发人员,我知道如何读写文件和小片段,但是正在寻找最好的逻辑或方法以任何编程语言来完成上述任务和脚本。
最佳答案
string url = "http://www.google.com";
var req = (HttpWebRequest)HttpWebRequest.Create(url);
req.AllowAutoRedirect = false;
using (var resp = req.GetResponse())
{
var location = resp.Headers["Location"];
if (!String.IsNullOrEmpty(location))
{
Console.WriteLine("url is redirected to " + location);
}
}
关于c# - 如何查找给定的URL是否将使用任何脚本重定向? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12329548/