HttpWebRequest.ConnectionGroupName 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置请求的连接组的名称。
public:
virtual property System::String ^ ConnectionGroupName { System::String ^ get(); void set(System::String ^ value); };
public override string? ConnectionGroupName { get; set; }
public override string ConnectionGroupName { get; set; }
member this.ConnectionGroupName : string with get, set
Public Overrides Property ConnectionGroupName As String
属性值
此请求的连接组的名称。 默认值为 null
。
示例
下面的代码示例演示如何使用用户信息形成连接组,前提是调用此代码之前,应用程序将设置变量 username
、password
和 domain
。
// Create a secure group name.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
SHA1Managed^ Sha1 = gcnew SHA1Managed;
array<Byte>^updHash = Sha1->ComputeHash( Encoding::UTF8->GetBytes( "usernamepassworddomain" ) );
String^ secureGroupName = Encoding::Default->GetString( updHash );
// Create a request for a specific URL.
WebRequest^ myWebRequest = WebRequest::Create( "http://www.contoso.com" );
// Set the authentication credentials for the request.
myWebRequest->Credentials = gcnew NetworkCredential( "username","password","domain" );
myWebRequest->ConnectionGroupName = secureGroupName;
// Get the response.
WebResponse^ myWebResponse = myWebRequest->GetResponse();
// Insert the code that uses myWebResponse here.
// Close the response.
myWebResponse->Close();
// Create a secure group name.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
SHA1Managed Sha1 = new SHA1Managed();
Byte[] updHash = Sha1.ComputeHash(Encoding.UTF8.GetBytes("username" + "password" + "domain"));
String secureGroupName = Encoding.Default.GetString(updHash);
// Create a request for a specific URL.
WebRequest myWebRequest=WebRequest.Create("http://www.contoso.com");
// Set the authentication credentials for the request.
myWebRequest.Credentials = new NetworkCredential("username", "password", "domain");
myWebRequest.ConnectionGroupName = secureGroupName;
// Get the response.
WebResponse myWebResponse=myWebRequest.GetResponse();
// Insert the code that uses myWebResponse here.
// Close the response.
myWebResponse.Close();
' Create a secure group name.
' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
Dim Sha1 As New SHA1Managed()
Dim updHash As [Byte]() = Sha1.ComputeHash(Encoding.UTF8.GetBytes(("username" + "password" + "domain")))
Dim secureGroupName As [String] = Encoding.Default.GetString(updHash)
' Create a request for a specific URL.
Dim myWebRequest As WebRequest = WebRequest.Create("http://www.contoso.com")
' Set the authentication credentials for the request.
myWebRequest.Credentials = New NetworkCredential("username", "password", "domain")
myWebRequest.ConnectionGroupName = secureGroupName
' Get the response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
' Insert the code that uses myWebResponse here.
' Close the response.
myWebResponse.Close()
注解
谨慎
WebRequest
、HttpWebRequest
、ServicePoint
和 WebClient
已过时,不应将其用于新开发。 请改用 HttpClient。
使用 ConnectionGroupName 属性可以将请求与连接组相关联。 当应用程序向不同用户(例如从数据库服务器检索客户信息的网站)向一台服务器发出请求时,这非常有用。
继承者说明
每个连接组都会为服务器创建其他连接。 这可能会导致超过该服务器的 ConnectionLimit 属性设置的连接数。