ServicePoint.Certificate 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得針對這個 ServicePoint 物件接收的憑證。
public:
property System::Security::Cryptography::X509Certificates::X509Certificate ^ Certificate { System::Security::Cryptography::X509Certificates::X509Certificate ^ get(); };
public System.Security.Cryptography.X509Certificates.X509Certificate? Certificate { get; }
public System.Security.Cryptography.X509Certificates.X509Certificate Certificate { get; }
member this.Certificate : System.Security.Cryptography.X509Certificates.X509Certificate
Public ReadOnly Property Certificate As X509Certificate
屬性值
X509Certificate 類別的實例,其中包含為此 ServicePoint 物件所接收的安全性憑證。
範例
下列程式代碼範例會顯示這個屬性的值。
if ( sp->Certificate == nullptr )
Console::WriteLine( "Certificate = (null)" );
else
Console::WriteLine( "Certificate = {0}", sp->Certificate );
if ( sp->ClientCertificate == nullptr )
Console::WriteLine( "Client Certificate = (null)" );
else
Console::WriteLine( "Client Certificate = {0}", sp->ClientCertificate );
Console::WriteLine( "ProtocolVersion = {0}", sp->ProtocolVersion->ToString() );
Console::WriteLine( "SupportsPipelining = {0}", sp->SupportsPipelining );
if (sp.Certificate == null)
Console.WriteLine("Certificate = (null)");
else
Console.WriteLine("Certificate = " + sp.Certificate.ToString());
if (sp.ClientCertificate == null)
Console.WriteLine("ClientCertificate = (null)");
else
Console. WriteLine("ClientCertificate = " + sp.ClientCertificate.ToString());
Console.WriteLine("ProtocolVersion = " + sp.ProtocolVersion.ToString());
Console.WriteLine("SupportsPipelining = " + sp.SupportsPipelining);
If sp.Certificate Is Nothing Then
Console.WriteLine("Certificate = (null)")
Else
Console.WriteLine(("Certificate = " + sp.Certificate.ToString()))
End If
If sp.ClientCertificate Is Nothing Then
Console.WriteLine("ClientCertificate = (null)")
Else
Console.WriteLine(("ClientCertificate = " + sp.ClientCertificate.ToString()))
End If
Console.WriteLine("ProtocolVersion = " + sp.ProtocolVersion.ToString())
Console.WriteLine(("SupportsPipelining = " + sp.SupportsPipelining.ToString()))
備註
謹慎
WebRequest
、HttpWebRequest
、ServicePoint
和 WebClient
已經過時,您不應該將它們用於新的開發。 請改用 HttpClient。
雖然 ServicePoint 物件可以對因特網資源進行多個連線,但它只能維護一個憑證。
注意
在 .NET Core 和 .NET 5+中,Certificate 屬性一律會傳回 null。 若要存取伺服器憑證,請使用 ServerCertificateCustomValidationCallback。