# CookieContainer란?
A CookieContainer is a data structure that provides storage for instances of the Cookie class, and which is accessed in a database-like manner. The CookieContainer has a capacity limit that is set when the container is created or changed by a property.
Cookie 클래스의 인스턴스를 위한 공간을 제공하는 데이터 구조이다. 쿠키에 db와 같이 접근 가능하고, 용량의 제한이 있다.
# namespace
- System.Net
# 생성
string requestBody = string.Empty
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest request = null;
request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST" or "GET"
request.Accpet = "application/json"
request.ContentType = "application/json"
request.PreAuthenticate = true
if (!requestBody.Equals(string.Empty)){
byts[] data = Encoding.UTF8.GetBytes(requestBody);
// request body 입력 방법
Stream dataStream = request.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Close();
}
request.Headers.Add("Authorization", "Basic <base64 계정 정보>");
request.CookieContainer = cookieContainer; // 전송 성공 후 쿠키 저장
using (response = request.GetResponse() as HttpWebResponse) // 요청 수행 후 응답 객체
{
var responseStream = response.GetResponseStream()
if (responseStream != null && responseStream != Stream.Null)
{
// response 출력 방법
var Reader = new StreamReader(responseStream);
retJson = Reader.ReadToEnd();
Reader.Close();
}
}
'[DEV] App Dev ∕ Web Front > Framework ∕ Asp.Net' 카테고리의 다른 글
[ASP.NET] 닷넷 웹앱 기초 (0) | 2020.12.29 |
---|---|
[ASP.NET] 한 큐에 정리하기 (0) | 2020.12.23 |
ASP.NET 기초 클래스 (0) | 2020.12.18 |
ASP.NET 기본 소스 구조 (0) | 2020.12.17 |
ASP.NET 기본 상식 (0) | 2020.12.17 |
최근댓글