C# Class NSoft.NFramework.Networks.HttpClient

Http 통신을 수행하는 Client Class
Show file Open project: debop/NFramework Class Usage Examples

Public Methods

Method Description
DownloadData ( ) : byte[]

해당주소에서 Data를 받습니다.

DownloadFile ( string address, string filename ) : bool

지정한 주소의 내용을 받아서 파일로 저장한다.

Get ( ) : string

URL정보를 기초로 HTTP GET 을 수행한다.

GetResponse ( string method = "Get" ) : WebResponse

응답 객체를 반환한다.

WebResponse는 사용한 후 꼭 Close를 호출해야 한다.

Head ( ) : WebHeaderCollection

응답 Header 내용을 반환한다.

HttpClient ( ) : System

Initialize a new instance of HttpClient.

HttpClient ( Uri baseUri ) : System

Initialize a new instance of HttpClient with baseUri.

HttpClient ( Uri baseUri, int timeout = HttpConsts.HTTP_DEFAULT_TIMEOUT, string userId = null, string passwd = null ) : System

Initialize a new instance of HttpClient with baseUri, timeout, user id and password

HttpClient ( string baseUriString ) : System

Initialize a new instance of HttpClient with uri string.

HttpClient ( string baseUriString, int timeout = HttpConsts.HTTP_DEFAULT_TIMEOUT, string userId = null, string passwd = null ) : System

Initialize a new instance of HttpClient with uri, timeout, user id and password

Post ( NameValueCollection inputs, Encoding enc = null ) : string

지정된 서버에 DATA를 POST 방식으로 전송한다.

Post ( string payload, Encoding enc = null ) : string

주어진 URL를 기초로 Http Post 를 수행한다. ASP.NET 서버인 경우 web.config의 Request/Response Encoding 정보를 잘 보고 해야 한다.

ResponseToArray ( WebResponse response ) : byte[]

Response 정보를 byte array로 변환한다.

길이가 아주 길고, 실제 크기를 알 수 없을 때 Response 개체의 stream을 처리하는 로직이 있음.

UploadFile ( string filename, string method = "POST" ) : byte[]

Client의 지정된 파일을 서버로 전송한다.

Private Methods

Method Description
BuildRequest ( ) : HttpWebRequest

요청 객체를 생성한다.

DisposeRequest ( ) : void

내부 Request 개체를 해제한다.

GetCredentials ( ) : ICredentials
GetUri ( Uri relativeUri ) : Uri
GetUri ( string relativePath ) : Uri

기본 Uri와 script path를 가지고 완전한 Uri를 만든다.

OnChanged ( ) : void
PrepareRequestHeaders ( WebRequest request ) : void

Http 메소드를 실행하기 위해 Http 요청 객체(HttpWebRequest)의 헤더 부분을 조정한다.

Method Details

DownloadData() public method

해당주소에서 Data를 받습니다.
public DownloadData ( ) : byte[]
return byte[]

DownloadFile() public method

지정한 주소의 내용을 받아서 파일로 저장한다.
public DownloadFile ( string address, string filename ) : bool
address string 서버 주소
filename string 로칼 파일 경로
return bool

Get() public method

URL정보를 기초로 HTTP GET 을 수행한다.
public Get ( ) : string
return string

GetResponse() public method

응답 객체를 반환한다.
WebResponse는 사용한 후 꼭 Close를 호출해야 한다.
public GetResponse ( string method = "Get" ) : WebResponse
method string 참고
return System.Net.WebResponse

Head() public method

응답 Header 내용을 반환한다.
public Head ( ) : WebHeaderCollection
return System.Net.WebHeaderCollection

HttpClient() public method

Initialize a new instance of HttpClient.
public HttpClient ( ) : System
return System

HttpClient() public method

Initialize a new instance of HttpClient with baseUri.
public HttpClient ( Uri baseUri ) : System
baseUri System.Uri 서버주소
return System

HttpClient() public method

Initialize a new instance of HttpClient with baseUri, timeout, user id and password
public HttpClient ( Uri baseUri, int timeout = HttpConsts.HTTP_DEFAULT_TIMEOUT, string userId = null, string passwd = null ) : System
baseUri System.Uri 서버주소
timeout int 통신 timeout (msec 단위)
userId string 사용자 Id
passwd string 비밀번호
return System

HttpClient() public method

Initialize a new instance of HttpClient with uri string.
public HttpClient ( string baseUriString ) : System
baseUriString string uri string
return System

HttpClient() public method

Initialize a new instance of HttpClient with uri, timeout, user id and password
public HttpClient ( string baseUriString, int timeout = HttpConsts.HTTP_DEFAULT_TIMEOUT, string userId = null, string passwd = null ) : System
baseUriString string uri string
timeout int time for http communication.
userId string user id
passwd string password
return System

Post() public method

지정된 서버에 DATA를 POST 방식으로 전송한다.
public Post ( NameValueCollection inputs, Encoding enc = null ) : string
inputs System.Collections.Specialized.NameValueCollection 전송 데이타
enc System.Text.Encoding 인코딩 방식
return string

Post() public method

주어진 URL를 기초로 Http Post 를 수행한다. ASP.NET 서버인 경우 web.config의 Request/Response Encoding 정보를 잘 보고 해야 한다.
public Post ( string payload, Encoding enc = null ) : string
payload string 전송할 DATA (ex PARAM1=VALUE1&PARAM2=VALUE2)
enc System.Text.Encoding 전송할 DATA의 Encoding 방식
return string

ResponseToArray() public static method

Response 정보를 byte array로 변환한다.
길이가 아주 길고, 실제 크기를 알 수 없을 때 Response 개체의 stream을 처리하는 로직이 있음.
public static ResponseToArray ( WebResponse response ) : byte[]
response System.Net.WebResponse
return byte[]

UploadFile() public method

Client의 지정된 파일을 서버로 전송한다.
public UploadFile ( string filename, string method = "POST" ) : byte[]
filename string 서버로 전송할 파일명
method string Http communication method. (GET, POST, PUT...)
return byte[]