+ Reply to Thread
Results 1 to 2 of 2

Thread: How to add cookies to CURL?

  1. #1
    Junior Member
    Join Date
    Jan 2012

    How to add cookies to CURL?

    I can post data using CURL , but i don't know how to add cookies to the CURL.

  2. #2
    Firstly you will need to import the Libcurl and it can be downloaded from : http://sourceforge.net/projects/libcurl-net/
    Then here is the snippet along with cookies.
            private void POST_DATA(string url, string data)
                Easy e = new Easy();
                string[] header = { "HTTP/1.1 200 OK Date: Tue, 06 Mar 2012 22:28:24 GMT Server: Apache Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: PHPSESSID=cq1viovgm2nvov3ovdftsfjg67; path=/ Vary: Accept-Encoding Cache-Control: max-age=600, private, must-revalidate Content-Length: 14161 Content-Type: text/html; charset=UTF-8", "content-type plain/text" };
    			// Here are our cookies , sure it it an invalid cookies but just to explain
                string Cookies = "tp%3A%2F%2Freauth%3D1;96ac124ba0d63d12613cd165e=zRaaaMT%7C/5ea4c711c2dc4ed62a821cgs-time-230=1345s=1; Mir=1345647600";
                e.SetOpt(CURLoption.CURLOPT_HEADER, true);
                e.SetOpt(CURLoption.CURLOPT_HTTPHEADER, header);
                e.SetOpt(CURLoption.CURLOPT_USERAGENT, "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101" /*"Mozilla/5.0 (Windows; U; Windows NT5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"*/);
                e.SetOpt(CURLoption.CURLOPT_COOKIE, Cookies); // COOKIES added alog with the request
                e.SetOpt(CURLoption.CURLOPT_TIMEOUT, 40); // The maximum number of seconds to allow cURL functions to execute.
                e.SetOpt(CURLoption.CURLOPT_CONNECTTIMEOUT, 20); // The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
                e.SetOpt(CURLoption.CURLOPT_URL, url);
                e.SetOpt(CURLoption.CURLOPT_POSTFIELDS, data);
    And you can use it like that :
    POST_DATA("http://website.com","POST DATA HERE");

+ Reply to Thread

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts