c# WebClient 쿠키 값 가져오는 방법

0 투표
using System;

using System.Collections.Generic;

using System.Net;

using System.Text;

using System.Threading.Tasks;

namespace Example

{

    public class CookieAwareWebClient : WebClient

    {

        public CookieAwareWebClient()

        {

            CookieContainer = new CookieContainer();

            this.ResponseCookies = new CookieCollection();

        }

        public CookieContainer CookieContainer { get; private set; }

        public CookieCollection ResponseCookies { get; set; }

        protected override WebRequest GetWebRequest(Uri address)

        {

            var request = (HttpWebRequest)base.GetWebRequest(address);

            request.CookieContainer = CookieContainer;

            return request;

        }

        protected override WebResponse GetWebResponse(WebRequest request)

        {

            var response = (HttpWebResponse)base.GetWebResponse(request);

            this.ResponseCookies = response.Cookies;

            return response;

        }

    }

}

1 답변

0 투표
string source = string.Empty;

CookieAwareWebClient webpage = new CookieAwareWebClient();

                webpage.Headers[System.Net.HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";

                webpage.Headers[System.Net.HttpRequestHeader.Referer] = TokenURL;

                source = webpage.DownloadString("http://www.nanumtip.com/qa/");

//webpage.ResponseCookies[0]
구로역 맛집 시흥동 맛집
이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
add
...