+ Reply to Thread
Results 1 to 2 of 2

Thread: CURL Post

  1. #1

    CURL Post

    Hey guys , i wanted to be able to send POST requests to server using CURL.
    why should i use CURL , i can do that using HTTP POST?
    Last edited by csharpmaster; 11-11-2012 at 09:35 AM.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    28
    Well , CURL is much faster plus the curl library you are going to use has more features and functions that will help you a lot.
    Ok lets get into it.

    What should you need ?
    The CURL library files and you can download it from here

    Okay steps :
    Once you extract the zip file you will download , head to bin directory and you will find 3 files :
    1-libcurl.dll
    2-LibCurlNet.dll
    3-LibCurlShim.dll

    Now create a project on visual studio and add reference : LibCurlNet.dll and it is only you will add to references

    Now type :
    Code:
    using SeasideResearch.LibCurlNet;
    Create a function :
    Code:
            private void post_data(string url, string data)
            {
                Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
    
                Easy e = new Easy();
                Easy.WriteFunction wf = MyWriteFunction;
    
                e.SetOpt(CURLoption.CURLOPT_URL, url);
                e.SetOpt(CURLoption.CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0");
                e.SetOpt(CURLoption.CURLOPT_POSTFIELDS, data);
                e.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
                e.Perform();
                e.Cleanup();
            }
    And add this function to receive a response stream.
    Code:
            private int MyWriteFunction(byte[] buf, int size, int nmemb, Object extraData)
            {
                StreamWriter sw = new StreamWriter(@"curl.txt");
    
                foreach (byte b in buf)
                {
                    sw.Write(((char)b));
                }
                sw.Flush();
                sw.Close();
                
                return buf.Length;
            }
    Now use it :
    Code:
    post_data("http://example.com", "POST DATA HERE");

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

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