Hi,
I have a windows form app which makes post httpwebrequests to the same pages
of the same web site several times. This web site generates a "phpsessid"
which is a session id residing in memory (no file is stored). It is a
parameter of the url of the second page :
Page1 : http://www.mydomain.com/mystartpage.php
Page2 : http;//www.mydomain.com/mysecondpage.php;phsessid=abed12ee65f...
My problem is : the cookie seems to stay in memory and I always get the same
session id where I would like to get a new one each time. I have spent hours
reading posts and searching the web and could not find a smarter solution
than killing the web session via the wininet API (!).
I must be doing something wrong... Some help would be greatly appreciated :-)
---
here is the (extract of) code :
myReq = DirectCast(WebRequest.Create(url), HttpWebRequest)
myReq.Timeout = m_Timeout
myReq.Referer = m_Referer
myReq.AllowAutoRedirect = True
myReq.CachePolicy = New
Cache.HttpRequestCachePolicy(Cache.HttpRequestCach eLevel.NoCacheNoStore)
myReq.CookieContainer = New CookieContainer
myReq.Method = "POST"
myReq.Accept = "*/*"
myReq.ContentType = m_ContentType
myReq.UserAgent = m_useragent
myReq.KeepAlive = False
'oCookies is a CookieCollection reset to nothing before each new set of
requests
If Not oCookies Is Nothing AndAlso oCookies.Count > 0 Then
myReq.CookieContainer.Add(oCookies)
End If
If postdata <> "" Then
byteArray = encodasc.GetBytes(postdata)
myReq.ContentLength = byteArray.Length
newStream = myReq.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)
newStream.Close()
End If
Try
myRep = myReq.GetResponse
myReq = Nothing
Catch exwe As Net.WebException
Return nothing
End Try
Dim enc As Encoding
enc = Encoding.GetEncoding(1252)
If myRep.ContentEncoding.Length > 0 Then
enc = Encoding.GetEncoding(myRep.ContentEncoding)
End If
Dim myRepStream As New StreamReader(myRep.GetResponseStream(), enc)
Dim myHTMLSourceCode As String = myRepStream.ReadToEnd
myRepStream.Close()
'update my headers vars
'...
If myRep.Cookies.Count > 0 Then
If oCookies Is Nothing Then
oCookies = myRep.Cookies
Else
Dim oRespCookie As Cookie, oReqCookie As Cookie
For Each oRespCookie In myRep.Cookies
Dim foundCookie As Boolean = False
For Each oReqCookie In oCookies
If oReqCookie.Name = oRespCookie.Name Then
oReqCookie.Value = oRespCookie.Value
foundCookie = True
Exit For
End If
Next
If Not foundCookie Then oCookies.Add(oRespCookie)
Next
End If
End If
myRep.Close()
Return myHTMLSourceCode
--
Xpou