Hello
I'm having trouble with cookies obtained through WebRequest and hope to find a solution here. I'm trying to submit form values using WebRequest
After I get the response, do the cookies obtained automatically get sent to the client browser? If not, how do I pass them to the client browser? I tried iterating through res.Cookies as well as webReq.CookieContainer.GetCookies("my uri"), and adding the cookie in this list to client using Response.Cookies.Add. But the problem is that even though I get the right cookie from the login_url, but when I use Response.Cookies.Add, the added cookie's DOMAIN changes from login_url to the web server's url, which are both different in my case, and renders the cookie useless. In a nutshell, the webserver is in the middle, which is trying to send the WebRequest to a different server, and simply pass on the obtained cookie to the client browser.
I'm having trouble with cookies obtained through WebRequest and hope to find a solution here. I'm trying to submit form values using WebRequest
Code:
Dim Login_Url As String = "<my url>"
Dim postData() As Byte = Encoding.ASCII.GetBytes("<my data>")
Dim webReq As HttpWebRequest = WebRequest.Create(Login_Url)
webReq.Method = "POST"
webReq.Headers.Add("Pragma", "no-cache")
webReq.Headers.Add("Expires", "0")
webReq.ContentType = "application/x-www-form-urlencoded"
webReq.ContentLength = postData.Length
webReq.CookieContainer = New CookieContainer
Dim stream As Stream = webReq.GetRequestStream
stream.Write(postData, 0, postData.Length)
stream.Flush()
stream.Close()
Dim res As HttpWebResponse = webReq.GetResponse
After I get the response, do the cookies obtained automatically get sent to the client browser? If not, how do I pass them to the client browser? I tried iterating through res.Cookies as well as webReq.CookieContainer.GetCookies("my uri"), and adding the cookie in this list to client using Response.Cookies.Add. But the problem is that even though I get the right cookie from the login_url, but when I use Response.Cookies.Add, the added cookie's DOMAIN changes from login_url to the web server's url, which are both different in my case, and renders the cookie useless. In a nutshell, the webserver is in the middle, which is trying to send the WebRequest to a different server, and simply pass on the obtained cookie to the client browser.