🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
6 messages
6 total messages Started by Richard Kavanagh Wed, 22 Nov 2006 10:50
TIdHTTP and Cookie (newby question)
#1690
Author: Richard Kavanagh
Date: Wed, 22 Nov 2006 10:50
45 lines
2035 bytes
I am having trouble with TIdHTTP and Cookies. I am attempting to notify a 
server that I am authorised to look at a certain page.

The cookie is stored in IE's cookie directory and looks like this:-




auth

7e5a7cec0769ed530cad95244bb62b44

einstein.phys.uwm.edu/

1536

3586013184

29892246

1595051984

29818821

*




Going from back to front, I assume the star is some terminating symbol, the 
previous four numbers are FILETIME numbers indicating I know what not. Not 
sure what 1536 stands for. The first two probably mean authority and some 
over-complicated password followed by the domain. Is this correct?

Looking at the Indy documentation there seems to be at least six ways to add 
this Cookie to a non-existing TIdCookieManager's CookieCollection. I have 
tried all six and none succeed.

Looking at past correspondence on the same or similar subjects all they say 
is that the CookieManager does it all for you, but there is no 
CookieManager. How do I instantiate one and more importantly initialize it 
with the above cookie?

Richard Kavanagh
Re: TIdHTTP and Cookie (newby question)
#1692
Author: Remy Lebeau (TeamB)
Date: Wed, 22 Nov 2006 17:54
70 lines
3301 bytes
"Richard Kavanagh" <dd.foldhill@google-ignore-mail.com> wrote in message
news:45642bbb$1@newsgroups.borland.com...

> The cookie is stored in IE's cookie directory and looks like this:-

Indy has no concept of IE's cookies (or any other browser's cookies, for
that matter).  You have to parse the cookie file yourself and then add it to
the CookieManager manually.

> Going from back to front, I assume the star is some terminating symbol

Yes.

> the previous four numbers are FILETIME numbers indicating I know what not.

From back to front, they are creation time high/low DWORDs and expire time
high/low DWORDs.  More specifically, they are Win32 API FILETIME values.

> Not sure what 1536 stands for.

Flags that control the cookie's behavior.

> The first two probably mean authority and some over-complicated password

They are the cookie's name and value.

> followed by the domain.

It is the domain and path that the cookie is valid for.

> Looking at past correspondence on the same or similar subjects all they
> say is that the CookieManager does it all for you

Correct.

> there is no CookieManager.

Yes, there is.  TIdHTTP has a CookieManager property of type
TIdCookieManager.  Such a component exists on the Component Palette.  If you
do not provide your own CookieManager object to that property, then a
default one is created internally when TIdHTTP sends a request.

> How do I instantiate one and more importantly initialize it with the above
cookie?

Indy's cookie support requires the cookie text to be formatted according to
how they are transmitted over HTTP, not how they are stored in files.
Cookie storage is a browser-specific operation.  Only the HTTP format is
standardized.  As such, you will have to load the cookie data from file and
re-format into a text value that Indy can consume properly.  For example:

    ULONG ulFlags = 1536;

    TIdCookieRFC2109 *Cookie =
IdHTTP1->CookieManager->CookieCollection->Add();

    Cookie->CookieName = "auth";
    Cookie->Value = "7e5a7cec0769ed530cad95244bb62b44";
    Cookie->Domain = "einstein.phys.uwm.edu";
    Cookie->Path = "/";
    Cookie->Secure = (ulFlags & 0x0001);

Refer to the following page for more details:

    HTTP::Cookies support for Microsoft Internet Explorer
    http://www.geocities.com/typopl/msieinfo.htm


Gambit
Re: TIdHTTP and Cookie (newby question)
#1693
Author: Richard Kavanagh
Date: Wed, 22 Nov 2006 18:31
86 lines
3987 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:45648f67@newsgroups.borland.com...
>
> "Richard Kavanagh" <dd.foldhill@google-ignore-mail.com> wrote in message
> news:45642bbb$1@newsgroups.borland.com...
>
>> The cookie is stored in IE's cookie directory and looks like this:-
>
> Indy has no concept of IE's cookies (or any other browser's cookies, for
> that matter).  You have to parse the cookie file yourself and then add it 
> to
> the CookieManager manually.
>
>> Going from back to front, I assume the star is some terminating symbol
>
> Yes.
>
>> the previous four numbers are FILETIME numbers indicating I know what 
>> not.
>
> From back to front, they are creation time high/low DWORDs and expire time
> high/low DWORDs.  More specifically, they are Win32 API FILETIME values.
>
>> Not sure what 1536 stands for.
>
> Flags that control the cookie's behavior.
>
>> The first two probably mean authority and some over-complicated password
>
> They are the cookie's name and value.
>
>> followed by the domain.
>
> It is the domain and path that the cookie is valid for.
>
>> Looking at past correspondence on the same or similar subjects all they
>> say is that the CookieManager does it all for you
>
> Correct.
>
>> there is no CookieManager.
>
> Yes, there is.  TIdHTTP has a CookieManager property of type
> TIdCookieManager.  Such a component exists on the Component Palette.  If 
> you
> do not provide your own CookieManager object to that property, then a
> default one is created internally when TIdHTTP sends a request.
>
>> How do I instantiate one and more importantly initialize it with the 
>> above
> cookie?
>
> Indy's cookie support requires the cookie text to be formatted according 
> to
> how they are transmitted over HTTP, not how they are stored in files.
> Cookie storage is a browser-specific operation.  Only the HTTP format is
> standardized.  As such, you will have to load the cookie data from file 
> and
> re-format into a text value that Indy can consume properly.  For example:
>
>    ULONG ulFlags = 1536;
>
>    TIdCookieRFC2109 *Cookie =
> IdHTTP1->CookieManager->CookieCollection->Add();
>
>    Cookie->CookieName = "auth";
>    Cookie->Value = "7e5a7cec0769ed530cad95244bb62b44";
>    Cookie->Domain = "einstein.phys.uwm.edu";
>    Cookie->Path = "/";
>    Cookie->Secure = (ulFlags & 0x0001);
>
> Refer to the following page for more details:
>
>    HTTP::Cookies support for Microsoft Internet Explorer
>    http://www.geocities.com/typopl/msieinfo.htm
>
>
> Gambit

Thanks Remy,
 This has given me a start. However there is still no CookieManager. IdHTTP 
has a property that is a pointer to something called CookieManager of type 
TIdCookieManager; however its value is NULL. So how do I instantiate and 
initialise one. The help files are not clear to me.
Richard
Re: TIdHTTP and Cookie (newby question)
#1694
Author: Richard Kavanagh
Date: Wed, 22 Nov 2006 18:53
11 lines
1353 bytes
>> there is no CookieManager.

Remy wrote:-

>
> Yes, there is.  TIdHTTP has a CookieManager property of type
> TIdCookieManager.  Such a component exists on the Component Palette.

Apologies. Found it. I did not look hard enough.
Richard 
Re: TIdHTTP and Cookie (newby question)
#1695
Author: Remy Lebeau (TeamB)
Date: Wed, 22 Nov 2006 19:32
16 lines
1721 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:45648f67@newsgroups.borland.com...

> Indy's cookie support requires the cookie text to be formatted according
> to how they are transmitted over HTTP, not how they are stored in files.
> Cookie storage is a browser-specific operation.  Only the HTTP format
> is standardized.  As such, you will have to load the cookie data from file
> and re-format into a text value that Indy can consume properly.

Ignore that statement.  It only applies if you are assigning the Cookie's
CookieText property, which I was going to do in my example originally, but
then decided to use the individual properties instead.


Gambit
Re: TIdHTTP and Cookie (newby question)
#1696
Author: Remy Lebeau (TeamB)
Date: Wed, 22 Nov 2006 19:36
30 lines
2058 bytes
"Richard Kavanagh" <dd.foldhill@google-ignore-mail.com> wrote in message
news:45649763@newsgroups.borland.com...

>  This has given me a start. However there is still no CookieManager.

Yes, there is.

> IdHTTP has a property that is a pointer to something called
> CookieManager of type TIdCookieManager

That is the propety to use.

> however its value is NULL.

You did not listen to what I said earlier.  TIdHTTP only creates its own
CookieManager when none is assigned by you prior to sending a request.  So
to fill in your own cookies beforehand, you will have to provide your own
CookieManager object to that property.

> So how do I instantiate and initialise one.

Then same way you do with any other component.  TIdCookieManager is a normal
component.  It is on the Component Palette, on the "Indy Misc" tab.  It has
a standard VCL constructor, so you can optionally instantiate it in code
instead of at design-time.  You don't have to do anything to "initialize" it
before adding your custom cookies to it.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads