I am currently trying to write an application which which can access certain links on a website. The website is protected by forms authentication and cookies. I have managed to pass the login information correctly as outlined in the code below.
Code:Dim CookieContainer As New CookieContainer Dim URL As String = "HTTP URL GOES HERE" Dim strPost As String = "POST_DATA_GOES HERE" Dim myWriter As StreamWriter Dim objRequest As HttpWebRequest = CType(WebRequest.Create(URL), HttpWebRequest) Dim cookies As CookieContainer = New CookieContainer 'objRequest.AllowWriteStreamBuffering = True objRequest.Method = "POST" objRequest.ContentType = "application/x-www-form-urlencoded" objRequest.CookieContainer = cookies myWriter = New StreamWriter(objRequest.GetRequestStream()) myWriter.Write(strPost) myWriter.Close() Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse) Dim str As StreamReader str = New StreamReader(objResponse.GetResponseStream) ' rtbresponse.Text = str.ReadToEnd myWriter.Close() objRequest.GetResponse().Close()
When I try to access another page on the same webserver, I am redirected back to the login page. Is there a way to share the stored cookies which each link that I visit?


Reply With Quote