Create Cookie in C#

  • Thread starter Thread starter Derek Jo
  • Start date Start date
D

Derek Jo

Hi all, I am new to C#. Currently, I need to write an
application in C# to retrieve page content from our web
site. (our web site is written in PHP, and some of the
pages is blocked by cookies.)

Can someone give me some sample of setting cookies in C#?
Please help

Derek
 
Derek,

I think that what you want to do is create a CookieContainer. Once you
have that, you can call the Add method to add a cookie to the container.
When you make the request, attach the CookieContainer to the request through
the CookieContainer property, and the container will send the cookies which
are part of the site, and it will be updated with the values of the cookies
when the response is retrieved.

Hope this helps.
 
Thanks Nicholas,

But would you please give me some reference or samples of
how to do this? I really haven't any idea about that...
Please help

Derek
-----Original Message-----
Derek,

I think that what you want to do is create a CookieContainer. Once you
have that, you can call the Add method to add a cookie to the container.
When you make the request, attach the CookieContainer to the request through
the CookieContainer property, and the container will send the cookies which
are part of the site, and it will be updated with the values of the cookies
when the response is retrieved.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi all, I am new to C#. Currently, I need to write an
application in C# to retrieve page content from our web
site. (our web site is written in PHP, and some of the
pages is blocked by cookies.)

Can someone give me some sample of setting cookies in C#?
Please help

Derek


.
 
Back
Top