NetworkCredential.GetCredential Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne une instance de la classe NetworkCredential pour le type d'authentification spécifié.
Surcharges
GetCredential(String, Int32, String) |
Retourne une instance de la classe NetworkCredential pour l'hôte, le port et le type d'authentification spécifiés. |
GetCredential(Uri, String) |
Retourne une instance de la classe NetworkCredential pour l'URI (Uniform Resource Identifier) et le type d'authentification spécifiés. |
GetCredential(String, Int32, String)
- Source:
- NetworkCredential.cs
- Source:
- NetworkCredential.cs
- Source:
- NetworkCredential.cs
Retourne une instance de la classe NetworkCredential pour l'hôte, le port et le type d'authentification spécifiés.
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
Paramètres
- host
- String
Ordinateur hôte qui authentifie le client.
- port
- Int32
Port sur host
avec lequel le client communique.
- authenticationType
- String
Type d'authentification demandé, tel que défini par la propriété AuthenticationType.
Retours
NetworkCredential de l’hôte, du port et du protocole d’authentification spécifiés, ou null
si aucune information d’identification n’est disponible pour l’hôte, le port et le protocole d’authentification spécifiés.
Implémente
Remarques
La valeur de authType
correspond à la IAuthenticationModule.AuthenticationType propriété .
S’applique à
GetCredential(Uri, String)
- Source:
- NetworkCredential.cs
- Source:
- NetworkCredential.cs
- Source:
- NetworkCredential.cs
Retourne une instance de la classe NetworkCredential pour l'URI (Uniform Resource Identifier) et le type d'authentification spécifiés.
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
Paramètres
- uri
- Uri
URI pour lequel le client fournit des informations d'identification.
- authTypeauthenticationType
- String
Type d'authentification demandé, tel que défini par la propriété AuthenticationType.
Retours
Objet NetworkCredential.
Implémente
Exemples
L’exemple de code suivant utilise la GetCredential méthode pour récupérer un NetworkCredential objet pour l’URI spécifié.
// 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()