You need a cookie container to accept/pass the cookies. Take a look at the
following snips. You may not need all of this but it should give you the
idea.
mgWebRequest =CType(WebReque st.Create(strWe bSite &
strWebPage),Htt pWebRequest)
mgWebRequest.ti meout = 90000
mgWebRequest.Co okieContainer = new cookiecontainer ()
mgWebRequest.re ferer = "whaterreff erer you want"
dim k as int32
Dim siteUri As New Uri(strWebSite)
'this add the current cookies to the container if you need to
for k = 0 to HttpContext.Cur rent.Request.Co okies.count - 1
dim ck as cookie = new cookie()
ck.name = HttpContext.Cur rent.Request.Co okies(k).name
ck.value = HttpContext.Cur rent.Request.Co okies(k).value
ck.domain = strWebSite.subs tring(strWebSit e.indexof(".") + 1)
ck.expires = datetime.now.ad dyears(50)
mgWebRequest.Co okieContainer.a dd(siteURI,ck)
next k
After you get the response you can use the following to add the receiving
cookies to your cookies
mgWebResponse = CType(mgWebRequ est.GetResponse (),HttpWebRespo nse)
mgWebResponse.c ookies =
mgWebrequest.Co okieContainer.G etCookies(mgWeb request.Request Uri)
mgStreamReader = New StreamReader(mg WebResponse.Get ResponseStream( ))
strText = mgStreamReader. ReadToEnd()
dim i as int32
for i = 0 to mgWebResponse.c ookies.count - 1
dim hc as httpcookie
hc = new httpcookie(mgWe bResponse.cooki es.item(i).name )
hc.value = mgWebResponse.c ookies.item(i). value
'hc.domain = "if you set this the whole thing will fail. Cannot
setdomain."
hc.expires = datetime.now.ad dyears(50)
hc.path = mgWebResponse.c ookies.item(i). path
HttpContext.Cur rent.Response.A ppendCookie(hc)
next i
mgStreamReader. Close()
"Peter" <an*******@disc ussions.microso ft.com> wrote in message
news:BA******** *************** ***********@mic rosoft.com...
Hi:
I am trying to do very simple http client that requires a login, copy
cookie snet by a server and does a request with the cookies.
WebRequest->CookieContaine r/WebResponse->Cookies does not seems to handle
cookie correctly.
User case: If a server send back cookies in headers that looks like
following:
Set-Cookie: a=assssa
Set-Cookie: b=asddasf
...
The WebResponse->Cookies only have one value from one Set-Cookie headers.
Yes, you can still see all the values in all Set-Cookie in
WebRespnose->Headers.
Do I miss something?
Peter