我有一个相当简单的程序,它接受一个 URL 并吐出它重定向到的第一个位置。无论如何,我一直在一些链接上对其进行测试,并注意到在一些 url 上出现 400 个错误。我尝试通过将其粘贴到我的浏览器中来测试这些 url,并且效果很好。
static string getLoc(string curLoc, out string StatusDescription, int timeoutmillseconds)
{
HttpWebRequest x = (HttpWebRequest)WebRequest.Create(curLoc);
x.UserAgent = "Opera/9.52 (Windows NT 6.0; U; en)";
x.Timeout = timeoutmillseconds;
x.AllowAutoRedirect = false;
HttpWebResponse y = null;
try
{
y = (HttpWebResponse)x.GetResponse(); //At this point it throws a 400 bad request exception.