Last post Aug 18, 2008 04:52 PM by Haissam
Aug 13, 2008 04:01 PM|greatbear|LINK
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
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.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)
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.
Any help greatly appreciated !!
Aug 13, 2008 05:19 PM|jsiddharthj|LINK
Use a tool called fiddler .It will help you what you are sending and
reciving back in a cookie.
Aug 13, 2008 05:32 PM|greatbear|LINK
Thanks Sid. I've used fiddler. But the problem is a bit different right now: The name/value pairs of cookies is just fine. The main problem is the domain of the cookie. The middleman, i.e the webserver needs to *pass on* the cookie obttained from the third
party server to the client browser. But when we use Response.Cookies.Add(cookie) in the script residing on web server, the domain of the cookie obtained from third party server gets changed to the domain value of web server. I'm wondering if there is a way
that the third party server sends the cookies directly to the client, by doing some modification in WebRequest object.
Aug 14, 2008 10:26 AM|Haissam|LINK
I dont think this can be achieved. As soon as you write the cookie retrieve from the third website to the Response object, its name will be changed by ur application domain name.
Aug 14, 2008 04:30 PM|greatbear|LINK
Thanks Haissam. On another thought, is it possible to make a WebRequest from ServerA to ServerB , and tell Server B to send response data to a Client X instead of Server A?
Aug 18, 2008 04:52 PM|Haissam|LINK
I dont think that is achievable also as the web server will return the response to the request sent by the user.