WebClient Class and Cookies

  • Thread starter Thread starter Paul J. Lay
  • Start date Start date
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
 
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.
 
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
 
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.
 
Back
Top