Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Components & Controls > Net / Sockets

Net / Sockets Components for network and related use

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-06-2008, 8:38 PM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 37
Reputation: 28
PutterPlace is on a distinguished programming path ahead
Default HttpWebRequest and Cookies

I'm having a problem with the cookies for my HttpWebRequest. First, I'm doing an HttpWebRequest to grab a PHP form from my site. When the PHP form is loaded, it set two cookies. Then I'm supposed to submit that form with those two cookies. My problem none of my request send the cookies that they're supposed to. Here's the gist of my code that's causing problems:

Code:
                Dim CookieJar as New CookieContainer()
                Try
                    Dim Stream As Stream
                    Dim Temp As String
                    Dim Request As HttpWebRequest = HttpWebRequest.Create(My.Settings.loginURL)
                    Request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14"
                    Dim Response As HttpWebResponse = Request.GetResponse()
                    Stream = Response.GetResponseStream
                    Dim tempCookie As Cookie
                    For Each tempCookie In Response.Cookies
                        CookieJar.Add(tempCookie)
                    Next
                    Temp = New StreamReader(Stream).ReadToEnd()
                    Stream.Close()
                    Response.Close()
                Catch ex As Exception
                End Try
                Try
                    Dim Stream As Stream
                    Dim Temp As String
                    Dim Request As HttpWebRequest = HttpWebRequest.Create(My.Settings.postURL)
                    Request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14"
                    Request.CookieContainer = CookieJar
                    Dim Response As HttpWebResponse = Request.GetResponse()
                    Stream = Response.GetResponseStream
                    Dim tempCookie As Cookie
                    For Each tempCookie In Response.Cookies
                        Debug.WriteLine(tempCookie.Name)
                        CookieList.Add(tempCookie)
                    Next
                    CookieJar.Add(CookieList)
                    Temp = New StreamReader(Stream).ReadToEnd()
                    Stream.Close()
                    Response.Close()
                Catch ex As Exception
                End Try
Can someone please help me find out what's wrong?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-07-2008, 9:32 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 37
Posts: 10,329
Reputation: 1315
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

try this (pseudo), it has worked for me before:
Code:
CookieJar = New CookieContainer

req1.create
req1.CookieContainer = CookieJar
req1.getresponse

req2.create
req2.CookieContainer = CookieJar 
req2.getresponse
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-07-2008, 10:38 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 37
Reputation: 28
PutterPlace is on a distinguished programming path ahead
Default

I will try that out, and post back with my results.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-07-2008, 3:37 PM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 37
Reputation: 28
PutterPlace is on a distinguished programming path ahead
Default

That worked like a charm. Thanks, JohnH.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On





All times are GMT -4. The time now is 4:58 AM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.