Configure connection and read timeout periods for API requests in the Classic SDK.
Important
Each API operation has a unique request object named in the ${API operation name}${Request} format, such as DescribeInstancesRequest.
Timeout periods
-
Connect Time: The timeout for establishing a TCP connection from the SDK to the server.
-
Read Time: the timeout for sending a request and receiving a complete response after a connection is established.
The Classic SDK applies timeout periods in the following priority order: request-level settings, client-level settings, and default values. The default connection timeout is 5 seconds, and the default read timeout is 10 seconds.
IClientProfile profile = DefaultProfile.GetProfile(
// The region ID.
"<your-region-id>",
// Obtain the AccessKey ID of the Resource Access Management (RAM) user from an environment variable.
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Obtain the AccessKey secret of the RAM user from an environment variable.
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
DefaultAcsClient client = new DefaultAcsClient(profile);
// Client-level timeout settings. These settings apply to all current requests.
DefaultAcsClient client = new DefaultAcsClient();
client.SetConnectTimeoutInMilliSeconds(1024);
client.SetReadTimeoutInMilliSeconds(2048);
// Request-level timeout settings. These settings apply only to the current request. The following code uses the DescribeInstancesRequest of ECS as an example.
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.SetConnectTimeoutInMilliSeconds(1024);
request.SetReadTimeoutInMilliSeconds(2048);