NetworkCredential.GetCredential Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Retorna uma instância da NetworkCredential classe para o tipo de autenticação especificado.
Sobrecargas
| Nome | Description |
|---|---|
| GetCredential(String, Int32, String) |
Retorna uma instância da NetworkCredential classe para o host, a porta e o tipo de autenticação especificados. |
| GetCredential(Uri, String) |
Retorna uma instância da NetworkCredential classe para o URI (Uniform Resource Identifier) e o tipo de autenticação especificados. |
GetCredential(String, Int32, String)
- Origem:
- NetworkCredential.cs
- Origem:
- NetworkCredential.cs
- Origem:
- NetworkCredential.cs
- Origem:
- NetworkCredential.cs
- Origem:
- NetworkCredential.cs
Retorna uma instância da NetworkCredential classe para o host, a porta e o tipo de autenticação especificados.
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
Parâmetros
- host
- String
O computador host que autentica o cliente.
- port
- Int32
A porta na qual o host cliente se comunica.
- authenticationType
- String
O tipo de autenticação solicitado, conforme definido na AuthenticationType propriedade.
Retornos
Um NetworkCredential para o host, a porta e o protocolo de autenticação especificados ou null se não houver credenciais disponíveis para o host, a porta e o protocolo de autenticação especificados.
Implementações
Comentários
O valor de authType corresponde à IAuthenticationModule.AuthenticationType propriedade.
Aplica-se a
GetCredential(Uri, String)
- Origem:
- NetworkCredential.cs
- Origem:
- NetworkCredential.cs
- Origem:
- NetworkCredential.cs
- Origem:
- NetworkCredential.cs
- Origem:
- NetworkCredential.cs
Retorna uma instância da NetworkCredential classe para o URI (Uniform Resource Identifier) e o tipo de autenticação especificados.
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
Parâmetros
- uri
- Uri
O URI para o qual o cliente fornece autenticação.
- authTypeauthenticationType
- String
O tipo de autenticação solicitado, conforme definido na AuthenticationType propriedade.
Retornos
Um NetworkCredential objeto.
Implementações
Exemplos
O exemplo de código a seguir usa o GetCredential método para recuperar um NetworkCredential objeto para o URI especificado.
// 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()