HttpClient 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
HTTP 요청을 보내고 URI로 식별된 리소스에서 HTTP 응답을 수신하기 위한 클래스를 제공합니다.
public ref class HttpClient : System::Net::Http::HttpMessageInvoker
public class HttpClient : System.Net.Http.HttpMessageInvoker
type HttpClient = class
inherit HttpMessageInvoker
Public Class HttpClient
Inherits HttpMessageInvoker
- 상속
예제
// HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks.
static readonly HttpClient client = new HttpClient();
static async Task Main()
{
// Call asynchronous network methods in a try/catch block to handle exceptions.
try
{
using HttpResponseMessage response = await client.GetAsync("http://www.contoso.com/");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
// Above three lines can be replaced with new helper method below
// string responseBody = await client.GetStringAsync(uri);
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
}
}
open System.Net.Http
// HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks.
let client = new HttpClient()
let main =
task {
// Call asynchronous network methods in a try/catch block to handle exceptions.
try
use! response = client.GetAsync "http://www.contoso.com/"
response.EnsureSuccessStatusCode() |> ignore
let! responseBody = response.Content.ReadAsStringAsync()
// Above three lines can be replaced with new helper method below
// let! responseBody = client.GetStringAsync uri
printfn $"{responseBody}"
with
| :? HttpRequestException as e ->
printfn "\nException Caught!"
printfn $"Message :{e.Message} "
}
main.Wait()
' HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks.
Shared ReadOnly client As HttpClient = New HttpClient()
Private Shared Async Function Main() As Task
' Call asynchronous network methods in a try/catch block to handle exceptions.
Try
Using response As HttpResponseMessage = Await client.GetAsync("http://www.contoso.com/")
response.EnsureSuccessStatusCode()
Dim responseBody As String = Await response.Content.ReadAsStringAsync()
' Above three lines can be replaced with new helper method below
' Dim responseBody As String = Await client.GetStringAsync(uri)
Console.WriteLine(responseBody)
End Using
Catch e As HttpRequestException
Console.WriteLine(Environment.NewLine & "Exception Caught!")
Console.WriteLine("Message :{0} ", e.Message)
End Try
End Function
설명
이 API에 대한 자세한 내용은 HttpClient에 대한 추가 API 비고를 참조하세요.
생성자
| Name | Description |
|---|---|
| HttpClient() |
이 인스턴스가 삭제될 때 삭제되는 클래스를 HttpClientHandler 사용하여 클래스의 HttpClient 새 인스턴스를 초기화합니다. |
| HttpClient(HttpMessageHandler, Boolean) |
제공된 처리기를 사용하여 클래스의 HttpClient 새 인스턴스를 초기화하고 이 인스턴스를 삭제할 때 해당 처리기를 삭제해야 하는지 여부를 지정합니다. |
| HttpClient(HttpMessageHandler) |
지정된 처리기를 사용하여 클래스의 HttpClient 새 인스턴스를 초기화합니다. 이 인스턴스가 삭제되면 처리기가 삭제됩니다. |
속성
| Name | Description |
|---|---|
| BaseAddress |
요청을 보낼 때 사용되는 인터넷 리소스의 URI(Uniform Resource Identifier)의 기본 주소를 가져오거나 설정합니다. |
| DefaultProxy |
전역 HTTP 프록시를 가져오거나 설정합니다. |
| DefaultRequestHeaders |
각 요청과 함께 전송해야 하는 헤더를 가져옵니다. |
| DefaultRequestVersion |
이 HttpClient 인스턴스에서 수행한 후속 요청에 사용되는 기본 HTTP 버전을 가져오거나 설정합니다. |
| DefaultVersionPolicy |
예를 들어 GetAsync(String)PostAsync(String, HttpContent)편의 메서드에서 암시적으로 생성된 요청에 대한 기본 버전 정책을 가져오거나 설정합니다. |
| MaxResponseContentBufferSize |
응답 콘텐츠를 읽을 때 버퍼링할 최대 바이트 수를 가져오거나 설정합니다. |
| Timeout |
요청 시간이 초과되기 전에 대기할 시간 간격을 가져오거나 설정합니다. |
메서드
| Name | Description |
|---|---|
| CancelPendingRequests() |
이 인스턴스에서 보류 중인 모든 요청을 취소합니다. |
| DeleteAsync(String, CancellationToken) |
취소 토큰을 비동기 작업으로 사용하여 지정된 URI에 DELETE 요청을 보냅니다. |
| DeleteAsync(String) |
지정된 URI에 DELETE 요청을 비동기 작업으로 보냅니다. |
| DeleteAsync(Uri, CancellationToken) |
취소 토큰을 비동기 작업으로 사용하여 지정된 URI에 DELETE 요청을 보냅니다. |
| DeleteAsync(Uri) |
지정된 URI에 DELETE 요청을 비동기 작업으로 보냅니다. |
| Dispose() |
관리되지 않는 리소스를 해제하고 관리되는 리소스를 삭제합니다 HttpMessageInvoker. (다음에서 상속됨 HttpMessageInvoker) |
| Dispose(Boolean) |
관리되는 리소스에 사용되는 관리되지 않는 리소스를 HttpClient 해제하고 필요에 따라 관리되는 리소스를 삭제합니다. |
| Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetAsync(String, CancellationToken) |
취소 토큰을 비동기 작업으로 사용하여 지정된 URI에 GET 요청을 보냅니다. |
| GetAsync(String, HttpCompletionOption, CancellationToken) |
HTTP 완료 옵션 및 취소 토큰을 비동기 작업으로 사용하여 지정된 URI에 GET 요청을 보냅니다. |
| GetAsync(String, HttpCompletionOption) |
HTTP 완료 옵션을 비동기 작업으로 사용하여 지정된 URI에 GET 요청을 보냅니다. |
| GetAsync(String) |
지정된 URI에 GET 요청을 비동기 작업으로 보냅니다. |
| GetAsync(Uri, CancellationToken) |
취소 토큰을 비동기 작업으로 사용하여 지정된 URI에 GET 요청을 보냅니다. |
| GetAsync(Uri, HttpCompletionOption, CancellationToken) |
HTTP 완료 옵션 및 취소 토큰을 비동기 작업으로 사용하여 지정된 URI에 GET 요청을 보냅니다. |
| GetAsync(Uri, HttpCompletionOption) |
HTTP 완료 옵션을 비동기 작업으로 사용하여 지정된 URI에 GET 요청을 보냅니다. |
| GetAsync(Uri) |
지정된 URI에 GET 요청을 비동기 작업으로 보냅니다. |
| GetByteArrayAsync(String, CancellationToken) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 바이트 배열로 반환합니다. |
| GetByteArrayAsync(String) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 바이트 배열로 반환합니다. |
| GetByteArrayAsync(Uri, CancellationToken) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 바이트 배열로 반환합니다. |
| GetByteArrayAsync(Uri) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 바이트 배열로 반환합니다. |
| GetHashCode() |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
| GetStreamAsync(String, CancellationToken) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 스트림으로 반환합니다. |
| GetStreamAsync(String) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 스트림으로 반환합니다. |
| GetStreamAsync(Uri, CancellationToken) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 스트림으로 반환합니다. |
| GetStreamAsync(Uri) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 스트림으로 반환합니다. |
| GetStringAsync(String, CancellationToken) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 문자열로 반환합니다. |
| GetStringAsync(String) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 문자열로 반환합니다. |
| GetStringAsync(Uri, CancellationToken) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 문자열로 반환합니다. |
| GetStringAsync(Uri) |
지정된 URI에 GET 요청을 보내고 비동기 작업에서 응답 본문을 문자열로 반환합니다. |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| PatchAsync(String, HttpContent, CancellationToken) |
취소 토큰이 있는 PATCH 요청을 문자열로 표시된 URI에 비동기 작업으로 보냅니다. |
| PatchAsync(String, HttpContent) |
문자열로 지정된 URI에 PATCH 요청을 비동기 작업으로 보냅니다. |
| PatchAsync(Uri, HttpContent, CancellationToken) |
취소 토큰이 있는 PATCH 요청을 비동기 작업으로 보냅니다. |
| PatchAsync(Uri, HttpContent) |
PATCH 요청을 비동기 작업으로 보냅니다. |
| PostAsync(String, HttpContent, CancellationToken) |
취소 토큰을 사용하여 POST 요청을 비동기 작업으로 보냅니다. |
| PostAsync(String, HttpContent) |
지정된 URI에 POST 요청을 비동기 작업으로 보냅니다. |
| PostAsync(Uri, HttpContent, CancellationToken) |
취소 토큰을 사용하여 POST 요청을 비동기 작업으로 보냅니다. |
| PostAsync(Uri, HttpContent) |
지정된 URI에 POST 요청을 비동기 작업으로 보냅니다. |
| PutAsync(String, HttpContent, CancellationToken) |
취소 토큰을 사용하여 PUT 요청을 비동기 작업으로 보냅니다. |
| PutAsync(String, HttpContent) |
지정된 URI에 PUT 요청을 비동기 작업으로 보냅니다. |
| PutAsync(Uri, HttpContent, CancellationToken) |
취소 토큰을 사용하여 PUT 요청을 비동기 작업으로 보냅니다. |
| PutAsync(Uri, HttpContent) |
지정된 URI에 PUT 요청을 비동기 작업으로 보냅니다. |
| Send(HttpRequestMessage, CancellationToken) |
지정된 요청 및 취소 토큰을 사용하여 HTTP 요청을 보냅니다. |
| Send(HttpRequestMessage, HttpCompletionOption, CancellationToken) |
지정된 요청, 완료 옵션 및 취소 토큰을 사용하여 HTTP 요청을 보냅니다. |
| Send(HttpRequestMessage, HttpCompletionOption) |
HTTP 요청을 보냅니다. |
| Send(HttpRequestMessage) |
지정된 요청을 사용하여 HTTP 요청을 보냅니다. |
| SendAsync(HttpRequestMessage, CancellationToken) |
HTTP 요청을 비동기 작업으로 보냅니다. |
| SendAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken) |
HTTP 요청을 비동기 작업으로 보냅니다. |
| SendAsync(HttpRequestMessage, HttpCompletionOption) |
HTTP 요청을 비동기 작업으로 보냅니다. |
| SendAsync(HttpRequestMessage) |
HTTP 요청을 비동기 작업으로 보냅니다. |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |