NetworkCredential.GetCredential Метод

Определение

Возвращает экземпляр класса NetworkCredential для заданных URI и типа проверки подлинности.Returns an instance of the NetworkCredential class for the specified authentication type.

Перегрузки

GetCredential(Uri, String)

Возвращает экземпляр класса NetworkCredential, связанный с указанным URI и типом проверки подлинности.Returns an instance of the NetworkCredential class for the specified Uniform Resource Identifier (URI) and authentication type.

GetCredential(String, Int32, String)

Возвращает экземпляр класса NetworkCredential для заданных узла, порта и типа проверки подлинности.Returns an instance of the NetworkCredential class for the specified host, port, and authentication type.

GetCredential(Uri, String)

Возвращает экземпляр класса NetworkCredential, связанный с указанным URI и типом проверки подлинности.Returns an instance of the NetworkCredential class for the specified Uniform Resource Identifier (URI) and authentication type.

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

Параметры

uri
Uri

URI, для получения доступа к которому клиент проходит проверку подлинности.The URI that the client provides authentication for.

authType
String

Тип запрашиваемой проверки подлинности согласно его определению в свойстве AuthenticationType.The type of authentication requested, as defined in the AuthenticationType property.

Возвращаемое значение

Реализации

Примеры

В следующем примере кода метод GetCredential используется для получения объекта NetworkCredential для указанного универсального кода ресурса (URI).The following code example uses the GetCredential method to retrieve a NetworkCredential object for the specified URI.

// 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 sucessfully" );

// 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 sucessfully");
// 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 sucessfully")
' Release the resources of the response object.
myWebResponse.Close()

GetCredential(String, Int32, String)

Возвращает экземпляр класса NetworkCredential для заданных узла, порта и типа проверки подлинности.Returns an instance of the NetworkCredential class for the specified host, port, and authentication type.

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);
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

узел, проверяющий подлинность клиента.The host computer that authenticates the client.

port
Int32

Порт на host, с которым клиент будет устанавливать связь.The port on the host that the client communicates with.

authenticationType
String

Тип запрашиваемой проверки подлинности согласно его определению в свойстве AuthenticationType.The type of authentication requested, as defined in the AuthenticationType property.

Возвращаемое значение

Учетные данные NetworkCredential для указанного узла, порта и протокола проверки подлинности или значение null, если для указанных узла, порта и протокола проверки подлинности не определены учетные данные.A NetworkCredential for the specified host, port, and authentication protocol, or null if there are no credentials available for the specified host, port, and authentication protocol.

Реализации

Комментарии

Значение authType соответствует свойству IAuthenticationModule.AuthenticationType.The value of authType corresponds to the IAuthenticationModule.AuthenticationType property.

Применяется к