Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > WebRequest Cookie

Reply
Thread Tools

WebRequest Cookie

 
 
greatbear greatbear is offline
Junior Member
Join Date: Aug 2008
Posts: 1
 
      08-13-2008
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cookie Question (IP as domain and cookie file location) =?Utf-8?B?UGF1bA==?= ASP .Net 1 01-10-2006 08:37 PM
Any downsides to cookie assignment inside custom class using HttpContext.Current? ASP.NET 2.0 cookie fix? ASP .Net 2 08-17-2005 06:43 AM
Cookie and Session Cookie Questions. Shapper ASP .Net 1 04-27-2005 11:20 AM
Session cookie? Browser instance cookie? Ben ASP .Net 3 06-03-2004 03:41 AM
Cookie question with WebRequest vMike ASP .Net 0 11-07-2003 07:01 PM



Advertisments