첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

728x90
반응형
728x170
using System.Net;
using System.Text;

#region 문자열 다운로드하기 - DownloadString(webClient, url)

/// <summary>
/// 문자열 다운로드하기
/// </summary>
/// <param name="webClient">웹 클라이언트</param>
/// <param name="url">URL</param>
/// <returns>다운로드 문자열</returns>
public string DownloadString(WebClient webClient, string url)
{
    const string charsetKey = "charset";

    byte[] dataByteArray = webClient.DownloadData(url);

    string contentType = webClient.ResponseHeaders["Content-Type"];

    int charsetPosition = contentType.IndexOf(charsetKey);

    Encoding currentEncoding = Encoding.Default;

    if(charsetPosition != -1)
    {
        charsetPosition = contentType.IndexOf("=", charsetPosition + charsetKey.Length);

        if(charsetPosition != -1)
        {
            string charset = contentType.Substring(charsetPosition + 1);

            currentEncoding = Encoding.GetEncoding(charset);
        }
    }

    return currentEncoding.GetString(dataByteArray);
}

#endregion
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요