NetworkCredential.GetCredential Metoda

Definice

Vrátí instanci NetworkCredential třídy pro zadaný typ ověřování.

Přetížení

GetCredential(String, Int32, String)

Vrátí instanci NetworkCredential třídy pro zadaného hostitele, port a typ ověřování.

GetCredential(Uri, String)

Vrátí instanci NetworkCredential třídy pro zadaný identifikátor URI (Uniform Resource Identifier) a typ ověřování.

GetCredential(String, Int32, String)

Zdroj:
NetworkCredential.cs
Zdroj:
NetworkCredential.cs
Zdroj:
NetworkCredential.cs

Vrátí instanci NetworkCredential třídy pro zadaného hostitele, port a typ ověřování.

public System.Net.NetworkCredential GetCredential (string host, int port, string authenticationType);
public System.Net.NetworkCredential GetCredential (string? host, int port, string? authenticationType);

Parametry

host
String

Hostitelský počítač, který ověřuje klienta.

port
Int32

Port na zařízení, se host kterým klient komunikuje.

authenticationType
String

Typ požadovaného ověřování, jak je definováno AuthenticationType ve vlastnosti .

Návraty

A NetworkCredential pro zadaného hostitele, port a ověřovací protokol nebo null pokud pro zadaného hostitele, port a ověřovací protokol nejsou k dispozici žádné přihlašovací údaje.

Implementuje

Poznámky

Hodnota odpovídá authTypeIAuthenticationModule.AuthenticationType vlastnosti .

Platí pro

.NET 9 a další verze
Produkt Verze
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

GetCredential(Uri, String)

Zdroj:
NetworkCredential.cs
Zdroj:
NetworkCredential.cs
Zdroj:
NetworkCredential.cs

Vrátí instanci NetworkCredential třídy pro zadaný identifikátor URI (Uniform Resource Identifier) a typ ověřování.

public System.Net.NetworkCredential GetCredential (Uri uri, string authType);
public System.Net.NetworkCredential GetCredential (Uri? uri, string? authenticationType);

Parametry

uri
Uri

Identifikátor URI, pro který klient poskytuje ověřování.

authTypeauthenticationType
String

Typ požadovaného ověřování, jak je definováno AuthenticationType ve vlastnosti .

Návraty

Objekt NetworkCredential .

Implementuje

Příklady

Následující příklad kódu používá metodu GetCredential k načtení objektu NetworkCredential pro zadaný identifikátor URI.

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

Platí pro

.NET 9 a další verze
Produkt Verze
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0