Download file through code that has a redirect?

前端 未结 2 607
太阳男子
太阳男子 2020-12-11 22:59

I have some urls in the database. The problem is there urls are urls that redirect to what I want.

I have something like this

http://www.mytestsite.com/test/

2条回答
  •  误落风尘
    2020-12-11 23:23

    I think you are after the HttpWebRequest.AllowAutoRedirect Property. The property gets or sets a value that indicates whether the request should follow redirection responses.

    Example taken from MSDN

    HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.contoso.com");    
    myHttpWebRequest.MaximumAutomaticRedirections=1;
    myHttpWebRequest.AllowAutoRedirect=true;
    HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
    

提交回复
热议问题