Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookies - sending saved values in httprequest

Status
Not open for further replies.

JavaDoctor

Technical User
Nov 26, 2004
7
GB
Hello, I'm just going around in circles with this so I'm hoping someone may know the answer here.

Scenario - my community website utilises cookies to persist login/role data to control what I can see in a web browser according to level. If I have logged in today my cookie means it will remember me for 60 days. Cool.

Problem - I want to use a Windows client (not a browser) to download the page source and parse certain data from the returned HTML source for pages I can see for my level when logged in. If I use VBScript :

Set http = CreateObject("Microsoft.XmlHttp")
http.Open "GET", " False
http.send "" etc etc...

No problem as this is recognised as a "browser" object and handles the cookie automatically

But I want to use VB.NET

Question:
How do I do the same as above and get the cookie handled automatically on requesting the page?? Surely there must be an equivalent? Alternatively how do I use the cookie information stored on my machine and send it with the httprequest so I am auth'd as per the cookie??

Help?

Many thanks
 
I'm starting to think this is as bad as figuring sockets out :) No-one seems to know what to do.

OK I've made some progress but still stuck. I can use the data in the required cookie and send it in the httprequest as hard-coded as a test. Of course I need this to be part of the request process. Surely there is a method to automatically find the cookie, extract the right property and make this happen? I can't find it.

Scenario:
Website uri is Page I want is I have logged in via browser and cookie is set
Cookie is C:\Docs\Own\Cooks\owner@www.pageiwant[1].txt
Property I want in cookie is ABCD which has been set to G7789Ooqdowjkc7rrFA28r5hp0f78e

Here is my test code that does the job:

Dim uri As New Uri("Dim cookUri As New Uri("Dim request As HttpWebRequest
Dim response As HttpWebResponse

Try
request = CType(WebRequest.Create(uri), HttpWebRequest)
request.CookieContainer = New CookieContainer
request.CookieContainer.SetCookies(cookUri, "LDUC=G7789Ooqdowjkc7rrFA28r5hp0f78e")

response = CType(request.GetResponse(), HttpWebResponse)

'Rest of code goes here

The above authenticates me using the cookie value as if I was using a browser. What is the best way to automate this for any client machine. There must be a way :)

TIA

JD/Simon
 
I'm really beginning to think the only way of doing this is to use reflection to find the cookie folder and suck out the string. That's pretty poor as a solution tho...or is it? Just seems like there should be a method somewhere to help???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top