WebRequest Cookie

Joined
Aug 13, 2008
Messages
1
Reaction score
0
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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top