Hello,
I am writing a simple httpwebrequest bot for a client, but for some reason i can't succeed in passing a single cookie.
I'll clarify in steps:
As far as i am now, i have the bot connecting and receiving the cookie, but its not passing it on to the next httpwebrequest.
The code:
If i check cook.Value after the second step, its empty. I dont understand whats going on here, can anyone point me in the right direction?
I am writing a simple httpwebrequest bot for a client, but for some reason i can't succeed in passing a single cookie.
I'll clarify in steps:
- Bot connects and gets cookie
- Bot tells the server its active
- Bot posts data to server
- Bots tells server its disconnecting
- Bot disconnects and quits
As far as i am now, i have the bot connecting and receiving the cookie, but its not passing it on to the next httpwebrequest.
The code:
Code:
Dim postStart As HttpWebRequest
postStart = DirectCast(WebRequest.Create(startURL), HttpWebRequest)
postStart.CookieContainer = tempcookies
postStart.Method = "GET"
postStart.ContentType = "application/x-www-form-urlencoded"
postStart.UserAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:2.0b4) Gecko/20100818 Firefox/4.0b4"
Dim startresponse As HttpWebResponse
startresponse = DirectCast(postStart.GetResponse(), HttpWebResponse)
tempcookies.Add(startresponse.Cookies)
Dim startreader As New StreamReader(startresponse.GetResponseStream())
Dim start As String
start = startreader.ReadToEnd
If InStr(start, "Connecting") Then
TohlaWorker.ReportProgress(0, start)
GoTo verbinden
ElseIf InStr(start, "5") Then
TohlaWorker.ReportProgress(0, "Connected")
gesprekcookie = tempcookies
Dim postStarttyping As HttpWebRequest
postStarttyping = DirectCast(WebRequest.Create(typeURL), HttpWebRequest)
postStarttyping.Method = "POST"
postStarttyping.ContentType = "application/x-www-form-urlencoded"
postStarttyping.CookieContainer = gesprekcookie
postStarttyping.UserAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:2.0b4) Gecko/20100818 Firefox/4.0b4"
Dim starttypingresponse As HttpWebResponse
starttypingresponse = DirectCast(postStarttyping.GetResponse(), HttpWebResponse)
Dim poststartreader As New StreamReader(starttypingresponse.GetResponseStream())
Dim reply As String
reply = poststartreader.ReadToEnd
If InStr(reply, "1") Then
TohlaWorker.ReportProgress(0, "Simulating typing..")
Else
TohlaWorker.ReportProgress(0, "Error simulating typing, starting over")
GoTo verbinden
End If