Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 닷넷코어
- DockerWindows
- IOCP 클라이언트
- docker
- IOCP 서버
- IOCP
- mongodb pss
- .dotnet Core 3.1 Install
- firefly3
- 윈도우10 WOL
- Wake On Lan
- Winsock
- ubuntu .net Core
- mongodb readonly
- docker desktop
- MySQL
- .netCore Install
- DockerDesktop
- wol
- Docker오류
- 도커마운트
- Firefly
- n8n
- Volume Mount
- 윈도우10 Wake On Lan
- 가계부
- n8n설치
- docker-compose
- mongo docker
- DockerVolume
Archives
- Today
- Total
;
C# HttpWebRequest 웹 파싱하기 본문
반응형
"프로젝트 - 참조추가" 를 클릭하셔서 아래 사진과 같이 체크를 해주시길 바랍니다.
//---------------------------------------- // WebRequest 사용하기 위하여 using System.Net; using System.IO; using System.Web; //---------------------------------------- static HttpWebRequest request; static HttpWebResponse response; static StreamReader readerPost; static Stream dataStrem; static string resResult = string.Empty;
참조를 추가 하신 뒤 해당 HttpWebRequest를 사용하기 위하여 선언을 해줍니다.
선언은 메인 부분이나 상단에 작성해주시면 됩니다.
아래 코드처럼 함수 안에서 바로 불러와 사용할수 있게 하기 위하여 미리 선언을 하였습니다.
string httpWebGET( string url, string Referer ) {
request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.Referer = Referer;
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
request.ContentType = "application/x-www-form-urlencoded";
request.Host = splitParsing(url, "http://", "/");
request.KeepAlive = true;
request.AllowAutoRedirect = false;
response = (HttpWebResponse)request.GetResponse();
readerPost = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8, true); // Encoding.GetEncoding("EUC-KR")
resResult = readerPost.ReadToEnd();
//Getcookie = response.GetResponseHeader("Set-Cookie"); // 쿠키정보 값을 확인하기 위해서
readerPost.Close();
response.Close();
return resResult;
}
예제 :
RTB1.Text = httpWebGET("http://windowshyun.tistory.com", "http://windowshyun.tistory.com");
RTB1.Text에 http://windowshyun.tistory.com의 웹페이지 소스코드를 전부 가져옵니다.
httpWebGet에서 코드를 보시면 splitParsing라는 함수가 있느데 해당 함수는 이전글에서 특정 글자 파싱하기에서 사용하는 함수를 사용한것 입니다.
해당 함수를 같이 사용하시면 정상적으로 파싱이 됩니다.
반응형
'C, C++, C#' 카테고리의 다른 글
| 정규식 자동 완성 사이트 (0) | 2018.01.25 |
|---|---|
| C# 비동기 클라이언트 소켓 예제 [ C# Asynchronous Client ] (2) | 2017.07.17 |
| C# 특정글자 파싱하기 SplitParsing (2) | 2017.06.28 |
| C언어 ODBC를 이용하여 특정 아이디의 데이터 찾아 뿌려주기 (0) | 2017.05.31 |
| IOCP 구조체 전송 & 구조체 받기 (0) | 2016.12.04 |
Comments