0

I'm using CurlSharp library to GET HTTP. This is the code I got at the moment:

    static void Main(string[] args)
    {
        Curl.GlobalInit(CurlInitFlag.All);
        using (var easy = new CurlEasy())
        {
            easy.Url = "http://stackoverflow.com/";
            easy.FollowLocation = true;      
            easy.WriteData = null;
            easy.WriteFunction = OnWriteData;

            easy.Perform();
        }
    }

    public static Int32 OnWriteData(Byte[] buf, Int32 size, Int32 nmemb, Object extraData)
    {
        Console.Write(System.Text.Encoding.UTF8.GetString(buf));
        return size * nmemb;
    }

But OnWriteData() is call many times. Is it possible to append buf in string to get all HTML content ?

LeMoussel
  • 5,290
  • 12
  • 69
  • 122

1 Answers1

0

I found a solution by do this :

    public static string sContent;

    public static Int32 OnWriteData(Byte[] buf, Int32 size, Int32 nmemb, Object extraData)
    {
        string encoding = "UTF-8";
        sContent += System.Text.Encoding.GetEncoding(encoding).GetString(buf);
        return size * nmemb;
    }
LeMoussel
  • 5,290
  • 12
  • 69
  • 122