WebRequest 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
URI(Uniform Resource Identifier)에 대한 요청을 만듭니다. 이 클래스는 abstract
클래스입니다.
public ref class WebRequest abstract
public ref class WebRequest abstract : MarshalByRefObject, System::Runtime::Serialization::ISerializable
public abstract class WebRequest
public abstract class WebRequest : MarshalByRefObject, System.Runtime.Serialization.ISerializable
[System.Serializable]
public abstract class WebRequest : MarshalByRefObject, System.Runtime.Serialization.ISerializable
type WebRequest = class
type WebRequest = class
inherit MarshalByRefObject
interface ISerializable
[<System.Serializable>]
type WebRequest = class
inherit MarshalByRefObject
interface ISerializable
Public MustInherit Class WebRequest
Public MustInherit Class WebRequest
Inherits MarshalByRefObject
Implements ISerializable
- 상속
-
WebRequest
- 상속
- 파생
- 특성
- 구현
예제
다음 예제에서는 instance 만들고 WebRequest 응답을 반환하는 방법을 보여줍니다.
#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Net;
using namespace System::Text;
int main()
{
// Create a request for the URL.
WebRequest^ request = WebRequest::Create( "http://www.contoso.com/default.html" );
// If required by the server, set the credentials.
request->Credentials = CredentialCache::DefaultCredentials;
// Get the response.
HttpWebResponse^ response = dynamic_cast<HttpWebResponse^>(request->GetResponse());
// Display the status.
Console::WriteLine( response->StatusDescription );
// Get the stream containing content returned by the server.
Stream^ dataStream = response->GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader^ reader = gcnew StreamReader( dataStream );
// Read the content.
String^ responseFromServer = reader->ReadToEnd();
// Display the content.
Console::WriteLine( responseFromServer );
// Cleanup the streams and the response.
reader->Close();
dataStream->Close();
response->Close();
}
using System;
using System.IO;
using System.Net;
using System.Text;
namespace Examples.System.Net
{
public class WebRequestGetExample
{
public static void Main ()
{
// Create a request for the URL.
WebRequest request = WebRequest.Create ("http://www.contoso.com/default.html");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
// Display the status.
Console.WriteLine (response.StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Cleanup the streams and the response.
reader.Close ();
dataStream.Close ();
response.Close ();
}
}
}
Imports System.IO
Imports System.Net
Imports System.Text
Namespace Examples.System.Net
Public Class WebRequestGetExample
Public Shared Sub Main()
' Create a request for the URL.
Dim request As WebRequest = WebRequest.Create("http://www.contoso.com/default.html")
' If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials
' Get the response.
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
' Display the status.
Console.WriteLine(response.StatusDescription)
' Get the stream containing content returned by the server.
Dim dataStream As Stream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
Console.WriteLine(responseFromServer)
' Cleanup the streams and the response.
reader.Close()
dataStream.Close()
response.Close()
End Sub
End Class
End Namespace
설명
중요
또는 파생 클래스를 새 개발에 사용하지 WebRequest
마세요. 대신는 System.Net.Http.HttpClient 클래스입니다.
WebRequest 는 의 abstract
기본 클래스입니다. 인터넷에서 데이터에 액세스하기 위한 NET의 요청/응답 모델입니다. 요청/응답 모델을 사용 하는 애플리케이션의 인스턴스를 사용 하 여 애플리케이션이 작동 하는 프로토콜 독립적인 방식으로 인터넷에서 데이터를 요청할 수는 WebRequest 프로토콜별 하위 항목 클래스의 세부 정보를 수행 하는 동안 클래스 요청입니다.
요청은 애플리케이션에서 서버의 웹 페이지와 같은 특정 URI로 전송 됩니다. 목록에서 만들려는 적절 한 하위 클래스를 결정 하는 URI WebRequest 하위 애플리케이션에 등록 합니다. WebRequest 하위 항목은 일반적으로 HTTP 또는 FTP와 같은 특정 프로토콜을 처리하도록 등록되지만 서버의 특정 서버 또는 경로에 대한 요청을 처리하도록 등록할 수 있습니다.
클래스는 WebRequest 인터넷 리소스에 WebException 액세스하는 동안 오류가 발생할 때 을 throw합니다. 속성은 Status 오류의 WebExceptionStatus 원인을 나타내는 값 중 하나입니다. 가 이WebExceptionStatus.ProtocolError면 Status 속성에 ResponseWebResponse 인터넷 리소스에서 받은 가 포함됩니다.
클래스는 WebRequest 클래스이므로 abstract
런타임에 인스턴스의 WebRequest 실제 동작은 메서드에서 반환된 하위 클래스에 Create 의해 결정됩니다. 기본값 및 예외에 대한 자세한 내용은 및 FileWebRequest와 같은 HttpWebRequest 하위 클래스에 대한 설명서를 참조하세요.
참고
메서드를 Create 사용하여 새 WebRequest 인스턴스를 초기화합니다. 생성자를 사용하지 WebRequest 마세요.
참고
일반 사용자의 자격 증명을 사용 하 여 실행 되는 WebRequest 개체를 만드는 애플리케이션 권한을 명시적으로 부여 되어 사용자에 게 이렇게 하려면 로컬 컴퓨터 저장소에 설치 된 인증서에 액세스할 수 없습니다.
구현자 참고
에서 WebRequest상속하는 경우 , , , HeadersRequestUriContentTypeContentLengthCredentialsEndGetRequestStream(IAsyncResult)BeginGetResponse(AsyncCallback, Object)PreAuthenticateGetRequestStream()BeginGetRequestStream(AsyncCallback, Object)GetResponse()및 EndGetResponse(IAsyncResult)멤버Method를 재정의해야 합니다. 또한 를 호출Create(Uri)할 때 사용되는 메서드를 정의하는 인터페이스의 IWebRequestCreate 구현을 Create(Uri) 제공해야 합니다. 메서드 또는 구성 파일을 사용하여 인터페이스를 IWebRequestCreate 구현하는 클래스를 RegisterPrefix(String, IWebRequestCreate) 등록해야 합니다.
생성자
WebRequest() |
사용되지 않음.
WebRequest 클래스의 새 인스턴스를 초기화합니다. |
WebRequest(SerializationInfo, StreamingContext) |
사용되지 않음.
WebRequest와 SerializationInfo 클래스에 지정된 인스턴스에서 StreamingContext 클래스의 새 인스턴스를 초기화합니다. |
속성
AuthenticationLevel |
이 요청에 사용되는 인증 및 가장 수준을 나타내는 값을 가져오거나 설정합니다. |
CachePolicy |
이 요청에 대한 캐시 정책을 가져오거나 설정합니다. |
ConnectionGroupName |
파생 클래스에서 재정의될 때 요청에 대한 연결 그룹 이름을 가져오거나 설정합니다. |
ContentLength |
서브클래스에서 재정의될 때, 전송 중인 요청 데이터의 콘텐츠 길이를 가져오거나 설정합니다. |
ContentType |
서브클래스에서 재정의될 때, 전송 중인 요청 데이터의 콘텐츠 형식을 가져오거나 설정합니다. |
CreatorInstance |
사용되지 않음.
하위 클래스에서 재정의될 때, 지정된 URI 에 요청하기 위해 인스턴스화된 WebRequest를 만드는 데 사용되는 IWebRequestCreate 클래스에서 파생된 팩터리 개체를 가져옵니다. |
Credentials |
서브클래스에서 재정의될 때, 인터넷 리소스를 사용하여 요청을 인증하는 데 사용되는 네트워크 자격 증명을 가져오거나 설정합니다. |
DefaultCachePolicy |
이 요청에 대한 기본 캐시 정책을 가져오거나 설정합니다. |
DefaultWebProxy |
글로벌 HTTP 프록시를 가져오거나 설정합니다. |
Headers |
서브클래스에서 재정의될 때, 요청과 연결된 헤더 이름/값 쌍의 컬렉션을 가져오거나 설정합니다. |
ImpersonationLevel |
현재 요청에 대한 가장 수준을 가져오거나 설정합니다. |
Method |
서브클래스에서 재정의될 때, 이 요청에서 사용할 프로토콜 메서드를 가져오거나 설정합니다. |
PreAuthenticate |
서브클래스에서 재정의될 때, 요청을 사전 인증할지 여부를 나타냅니다. |
Proxy |
서브클래스에서 재정의될 때, 이 인터넷 리소스에 액세스하기 위해 사용할 네트워크 프록시를 가져오거나 설정합니다. |
RequestUri |
서브클래스에서 재정의될 때, 요청과 연결된 인터넷 리소스의 URI를 가져옵니다. |
Timeout |
요청이 시간 초과되기 전의 시간(밀리초)을 가져오거나 설정합니다. |
UseDefaultCredentials |
서브클래스에서 재정의된 경우 Boolean를 요청과 함께 보낼지 여부를 제어하는 DefaultCredentials 값을 가져오거나 설정합니다. |
메서드
Abort() |
요청을 중단합니다. |
BeginGetRequestStream(AsyncCallback, Object) |
서브클래스에서 재정의될 때, GetRequestStream() 메서드의 비동기 버전을 제공합니다. |
BeginGetResponse(AsyncCallback, Object) |
서브클래스에서 재정의될 때, 인터넷 리소스에 대한 비동기 요청을 시작합니다. |
Create(String) |
사용되지 않음.
지정된 URI 체계에 대한 새 WebRequest 인스턴스를 초기화합니다. |
Create(Uri) |
사용되지 않음.
지정된 URI 체계에 대한 새 WebRequest 인스턴스를 초기화합니다. |
CreateDefault(Uri) |
사용되지 않음.
지정된 URI 체계에 대한 새 WebRequest 인스턴스를 초기화합니다. |
CreateHttp(String) |
사용되지 않음.
지정된 URI 문자열에 대한 새 HttpWebRequest 인스턴스를 초기화합니다. |
CreateHttp(Uri) |
사용되지 않음.
지정된 URI에 대한 새 HttpWebRequest 인스턴스를 초기화합니다. |
CreateObjRef(Type) |
원격 개체와 통신하는 데 사용되는 프록시 생성에 필요한 모든 관련 정보가 들어 있는 개체를 만듭니다. (다음에서 상속됨 MarshalByRefObject) |
EndGetRequestStream(IAsyncResult) |
서브클래스에서 재정의될 때, 인터넷 리소스에 데이터를 쓰기 위해 Stream을 반환합니다. |
EndGetResponse(IAsyncResult) |
파생 클래스에서 재정의될 때, WebResponse를 반환합니다. |
Equals(Object) |
지정된 개체가 현재 개체와 같은지 확인합니다. (다음에서 상속됨 Object) |
GetHashCode() |
기본 해시 함수로 작동합니다. (다음에서 상속됨 Object) |
GetLifetimeService() |
사용되지 않음.
이 인스턴스의 수명 정책을 제어하는 현재의 수명 서비스 개체를 검색합니다. (다음에서 상속됨 MarshalByRefObject) |
GetObjectData(SerializationInfo, StreamingContext) |
사용되지 않음.
대상 개체를 직렬화하는 데 필요한 데이터로 SerializationInfo를 채웁니다. |
GetRequestStream() |
서브클래스에서 재정의될 때, 인터넷 리소스에 데이터를 쓰기 위해 Stream을 반환합니다. |
GetRequestStreamAsync() |
서브클래스에서 재정의될 때, 인터넷 리소스에 비동기 작업으로 데이터를 쓰기 위해 Stream을 반환합니다. |
GetResponse() |
서브클래스에 재정의될 때, 인터넷 요청에 대한 응답을 반환합니다. |
GetResponseAsync() |
서브클래스에 재정의될 때, 인터넷 요청에 대한 응답을 비동기 작업으로 반환합니다. |
GetSystemWebProxy() |
현재 가장한 사용자의 Internet Explorer 설정에 구성된 프록시를 반환합니다. |
GetType() |
현재 인스턴스의 Type을 가져옵니다. (다음에서 상속됨 Object) |
InitializeLifetimeService() |
사용되지 않음.
이 인스턴스의 수명 정책을 제어하는 수명 서비스 개체를 가져옵니다. (다음에서 상속됨 MarshalByRefObject) |
MemberwiseClone() |
현재 Object의 단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
MemberwiseClone(Boolean) |
현재 MarshalByRefObject 개체의 단순 복사본을 만듭니다. (다음에서 상속됨 MarshalByRefObject) |
RegisterPortableWebRequestCreator(IWebRequestCreate) |
사용되지 않음.
IWebRequestCreate 개체를 등록합니다. |
RegisterPrefix(String, IWebRequestCreate) |
지정된 URI에 대한 WebRequest 하위 항목을 등록합니다. |
ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
명시적 인터페이스 구현
ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
사용되지 않음.
서브클래스에서 재정의될 때, SerializationInfo를 serialize하는 데 필요한 데이터로 WebRequest 인스턴스를 채웁니다. |
적용 대상
추가 정보
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기