WebClient Class and Cookies

P

Paul J. Lay

I have a Winforms App which uses the WebClient class and works very well. I
am wondering if I can look at cookies returned from the server as a result
of a WebClient class request. It appears that there is a WebClient
attribute called credentials which can be used to set and get credentials
for authentication. Is this the correct interface to look at cookies
returned by the server for encryption? Please advise. Thanks very much for
your help.

Best Regards,

Paul J. Lay
 
J

Jon Skeet [C# MVP]

Paul J. Lay said:
I have a Winforms App which uses the WebClient class and works very well. I
am wondering if I can look at cookies returned from the server as a result
of a WebClient class request. It appears that there is a WebClient
attribute called credentials which can be used to set and get credentials
for authentication. Is this the correct interface to look at cookies
returned by the server for encryption? Please advise. Thanks very much for
your help.

No, for cookies you should use HttpWebRequest and HttpWebResponse,
which allows you to set and retrieve cookies. You *could* modify the
Headers property of WebClient appropriately yourself, but I've
certainly had good results with HttpWebRequest.
 
P

Paul J. Lay

Thanks for your prompt reply. Can I use the HttpWebRequest and
HttpWebResponse in conjunction with my WebClient requests or do I have to
change all of my calls to use HttpWebRequest and HttpWebResponse? Do I
need to see the cookies or can I use the WebClient credentials property for
a authentication? Thanks very much for your help.

Best Regards,

Paul J. Lay
 
J

Jon Skeet [C# MVP]

Paul J. Lay said:
Thanks for your prompt reply. Can I use the HttpWebRequest and
HttpWebResponse in conjunction with my WebClient requests or do I have to
change all of my calls to use HttpWebRequest and HttpWebResponse? Do I
need to see the cookies or can I use the WebClient credentials property for
a authentication? Thanks very much for your help.

Cookies and credentials are entirely different things. You might be
able to get away with "mixing and matching" between HttpWebRequest and
WebClient, but personally I'd just use HttpWebRequest consistently -
it's powerful and still fairly simple to use.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top