power_settings_new
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
...