Configure HTTPS and TLS settings in the SDK
Alibaba Cloud SDK V2.0 for Go uses HTTPS for all API requests and validates TLS certificates by default. You can customize these settings for specific compliance requirements or isolated test environments.
Client-level configuration (Config object)
Configure the protocol when you initialize the SDK client. These settings apply to all requests made by that client instance.
Set the request protocol
The SDK sends all requests over HTTPS by default. While you can override this for legacy endpoints that only support HTTP, we strongly recommend using HTTPS to protect your data in transit.
Using HTTP sends your request data, including credentials, in clear text. Only use HTTP in trusted, isolated environments.
import (
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
)
config := &openapi.Config{
// This example overrides the secure default to use HTTP.
Protocol: tea.String("HTTP"),
}
Request-level configuration (RuntimeOptions object)
To configure settings for a single API call, pass a RuntimeOptions object. This is useful for temporarily disabling certificate validation during testing.
Disable TLS certificate validation
The SDK validates TLS certificates for all HTTPS requests by default. In non-production or test environments, such as when using a proxy with a self-signed certificate, you may need to temporarily disable this validation.
Disabling certificate validation is a security risk. Only use this option for testing in trusted environments. Never disable certificate validation in production code.
import (
util "github.com/alibabacloud-go/tea-utils/v2/service"
)
// This option skips certificate validation for a single API call.
runtime := &util.RuntimeOptions{}
runtime.IgnoreSSL = tea.Bool(true)