WebRequest Cookie

Discussion in '.NET' started by greatbear, Aug 13, 2008.

  1. greatbear

    greatbear

    Joined:
    Aug 13, 2008
    Messages:
    1
    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.
    greatbear, Aug 13, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vMike

    Cookie question with WebRequest

    vMike, Nov 7, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    384
    vMike
    Nov 7, 2003
  2. Ben
    Replies:
    3
    Views:
    5,826
    Steven Cheng[MSFT]
    Jun 3, 2004
  3. Shapper

    Cookie and Session Cookie Questions.

    Shapper, Apr 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    562
  4. =?Utf-8?B?UGF1bA==?=

    Cookie Question (IP as domain and cookie file location)

    =?Utf-8?B?UGF1bA==?=, Jan 10, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,470
    Bruce Barker
    Jan 10, 2006
  5. ad
    Replies:
    2
    Views:
    7,488
    Kevin Spencer
    Jan 27, 2006
Loading...

Share This Page