我正在使用CurlSharp库来获取HTTP。这是我目前得到的代码:
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;
}
但OnWriteData()
多次通话。是否可以在字符串中附加buf
以获取所有HTML内容?
答案 0 :(得分:0)
我通过这样做找到了解决方案:
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;
}