HTTP GET을 위해 CurlSharp 라이브러리를 사용 하고 있습니다. 이것은 내가 지금 얻은 코드입니다.
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 내용을 얻기 위해 문자열 에 추가 할 수 있습니까?
이 방법으로 해결책을 찾았습니다.
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;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다