Sachin Kalia

Sachin Kalia

  • NA
  • 24k
  • 9m

Get Cookies from give URl

Nov 21 2012 10:30 AM
Hello Champs

I am stuck up at a point ,where i want to retrieve the value of cookies from given URL.
like I have hit www.gmail.com in web browser and got the request from the web fiddler is given below.

I want to retrieve that cookie value present in we URL request .


e.g 

Host: mail.google.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: PREF=ID=0cc23a5dee20f170:U=b9a2b3d04573a026:LD=en:TM=1304058576:LM=1352184577:GM=1:S=9aFPLDIblkTcPEFU; NID=65=h7fGdRr57bGS_HZIWFyNc6wKho18UPDbR66ASp1ectNmDM1H7zkaccfIXxYrZX1LOEFV8BEIMQ8s-9o5GsCDb85w2UDEAXMgraMrCci37LR8-JhuKzcUVW_UgBhV_GlyeasaTUdah32-JI8cFKEo1LFAxJ3PBsY4; GMAIL_RTT=479




I've tried the given below code but didn't succeed 


        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.gmail.com/");
        CookieContainer cookies = new CookieContainer();
        CookieCollection cookieColl = req.CookieContainer.GetCookies(req.RequestUri);

I want to retrieve the given below colection 

Cookie: PREF=ID=0cc23a5dee20f170:U=b9a2b3d04573a026:LD=en:TM=1304058576:LM=1352184577:GM=1:S=9aFPLDIblkTcPEFU; NID=65=h7fGdRr57bGS_HZIWFyNc6wKho18UPDbR66ASp1ectNmDM1H7zkaccfIXxYrZX1LOEFV8BEIMQ8s-9o5GsCDb85w2UDEAXMgraMrCci37LR8-JhuKzcUVW_UgBhV_GlyeasaTUdah32-JI8cFKEo1LFAxJ3PBsY4; GMAIL_RTT=479



Any help would be highly appriciated,

Thanks Geeks.

Answers (1)