NetworkCredential.GetCredential 메서드

정의

지정된 인증 형식에 대한 NetworkCredential 클래스의 인스턴스를 반환합니다.

오버로드

GetCredential(String, Int32, String)

지정된 호스트, 포트 및 인증 형식에 대한 NetworkCredential 클래스의 인스턴스를 반환합니다.

GetCredential(Uri, String)

지정된 URI(Uniform Resource Identifier) 및 인증 형식에 대한 NetworkCredential 클래스의 인스턴스를 반환합니다.

GetCredential(String, Int32, String)

Source:
NetworkCredential.cs
Source:
NetworkCredential.cs
Source:
NetworkCredential.cs

지정된 호스트, 포트 및 인증 형식에 대한 NetworkCredential 클래스의 인스턴스를 반환합니다.

public:
 virtual System::Net::NetworkCredential ^ GetCredential(System::String ^ host, int port, System::String ^ authenticationType);
public System.Net.NetworkCredential GetCredential (string host, int port, string authenticationType);
public System.Net.NetworkCredential GetCredential (string? host, int port, string? authenticationType);
abstract member GetCredential : string * int * string -> System.Net.NetworkCredential
override this.GetCredential : string * int * string -> System.Net.NetworkCredential
Public Function GetCredential (host As String, port As Integer, authenticationType As String) As NetworkCredential

매개 변수

host
String

클라이언트를 인증하는 호스트 컴퓨터입니다.

port
Int32

클라이언트가 통신하는 host의 포트입니다.

authenticationType
String

AuthenticationType 속성에 정의된 대로 요청된 인증 형식입니다.

반환

지정된 호스트, 포트 및 인증 프로토콜에 대한 NetworkCredential이거나, 지정된 호스트, 포트 및 인증 프로토콜에 대해 사용할 수 있는 자격 증명이 없는 경우 null입니다.

구현

설명

authType 값은 속성에 IAuthenticationModule.AuthenticationType 해당합니다.

적용 대상

GetCredential(Uri, String)

Source:
NetworkCredential.cs
Source:
NetworkCredential.cs
Source:
NetworkCredential.cs

지정된 URI(Uniform Resource Identifier) 및 인증 형식에 대한 NetworkCredential 클래스의 인스턴스를 반환합니다.

public:
 virtual System::Net::NetworkCredential ^ GetCredential(Uri ^ uri, System::String ^ authType);
public:
 virtual System::Net::NetworkCredential ^ GetCredential(Uri ^ uri, System::String ^ authenticationType);
public System.Net.NetworkCredential GetCredential (Uri uri, string authType);
public System.Net.NetworkCredential GetCredential (Uri? uri, string? authenticationType);
abstract member GetCredential : Uri * string -> System.Net.NetworkCredential
override this.GetCredential : Uri * string -> System.Net.NetworkCredential
abstract member GetCredential : Uri * string -> System.Net.NetworkCredential
override this.GetCredential : Uri * string -> System.Net.NetworkCredential
Public Function GetCredential (uri As Uri, authType As String) As NetworkCredential
Public Function GetCredential (uri As Uri, authenticationType As String) As NetworkCredential

매개 변수

uri
Uri

클라이언트에서 인증을 제공하는 URI입니다.

authTypeauthenticationType
String

AuthenticationType 속성에 정의된 대로 요청된 인증 형식입니다.

반환

NetworkCredential 개체입니다.

구현

예제

다음 코드 예제에서는 메서드를 GetCredential 사용하여 지정된 URI에 대한 개체를 검색 NetworkCredential 합니다.

// Create an empty instance of the NetworkCredential class.
NetworkCredential^ myCredentials = gcnew NetworkCredential( userName,password );

// Create a webrequest with the specified URL.
WebRequest^ myWebRequest = WebRequest::Create( url );
myWebRequest->Credentials = myCredentials->GetCredential( gcnew Uri( url ), "" );
Console::WriteLine( "\n\nUser Credentials:- UserName : {0} , Password : {1}",
   myCredentials->UserName, myCredentials->Password );

// Send the request and wait for a response.
Console::WriteLine( "\n\nRequest to Url is sent.Waiting for response...Please wait ..." );
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Process the response.
Console::WriteLine( "\nResponse received successfully" );

// Release the resources of the response object.
myWebResponse->Close();
// Create an empty instance of the NetworkCredential class.
NetworkCredential myCredentials = new NetworkCredential(userName,password);
// Create a webrequest with the specified URL.
WebRequest myWebRequest = WebRequest.Create(url);
myWebRequest.Credentials = myCredentials.GetCredential(new Uri(url),"");
Console.WriteLine("\n\nUser Credentials:- UserName : {0} , Password : {1}",myCredentials.UserName,myCredentials.Password);
// Send the request and wait for a response.
Console.WriteLine("\n\nRequest to Url is sent.Waiting for response...Please wait ...");
WebResponse myWebResponse = myWebRequest.GetResponse();
// Process the response.
   Console.WriteLine("\nResponse received successfully");
// Release the resources of the response object.
myWebResponse.Close();
' Create an empty instance of the NetworkCredential class.
Dim myCredentials As New NetworkCredential(userName, password)
' Create a WebRequest with the specified URL. 
Dim myWebRequest As WebRequest = WebRequest.Create(url)
' GetCredential returns the same NetworkCredential instance that invoked it, 
' irrespective of what parameters were provided to it. 
 myWebRequest.Credentials = myCredentials.GetCredential(New Uri(url), "")
Console.WriteLine(ControlChars.Cr + ControlChars.Cr + "User Credentials:- UserName : {0} , Password : {1}", myCredentials.UserName, myCredentials.Password)
' Send the request and wait for a response.
Console.WriteLine(ControlChars.Cr + ControlChars.Cr + "Request to Url is sent.Waiting for response...Please wait ...")
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
' Process the response.
Console.WriteLine(ControlChars.Cr + "Response received successfully")
' Release the resources of the response object.
myWebResponse.Close()

적용 대상