This topic describes how to configure an HTTPS request in Alibaba Cloud SDK V2.0 for Node.js.
Alibaba Cloud SDK V2.0 for Node.js allows you to specify a protocol over which API requests are sent for an SDK client in the Config object. We recommend that you specify HTTPS as the protocol to improve the security of data transmission. If you do not specify the protocol, API requests are sent over HTTPS by default.
// Specify HTTPS as the protocol over which API requests are sent.
const config = new $OpenApi.Config({
protocol: 'https',
});
By default, if you send an API request over HTTPS, the SDK enables certificate verification to verify the validity of SSL/TLS certificates. If no certificate is configured in the development environment, an error that indicates the certificate verification fails is reported.
To ensure network communication security, we recommend that you enable certificate verification. If certificate verification must be disabled in the test environment, you can set the ignoreSSL
parameter to true when you specify runtime parameters.
const runtime = new $Util.RuntimeOptions({
// A value of true specifies to disable certificate verification. A value of false specifies to enable certificate verification.
ignoreSSL: true,
});
TypeScript:
import Ecs20140526, * as $Ecs20140526 from '@alicloud/ecs20140526';
import * as $OpenApi from '@alicloud/openapi-client';
import Credential from '@alicloud/credentials';
import Util, * as $Util from '@alicloud/tea-util';
export default class Client {
static async main(): Promise<void> {
// The default credential.
const cred = new Credential();
const config = new $OpenApi.Config({
credential: cred,
// The endpoint of an Alibaba Cloud service.
endpoint: "ecs.cn-beijing.aliyuncs.com",
protocol: 'https',
});
const client = new Ecs20140526(config);
const request = new $Ecs20140526.ModifySecurityGroupRuleRequest({
regionId: 'cn-beijing',
securityGroupId: 'sg-2zec0dm6qi66XXXXXXXX',
securityGroupRuleId: 'sgr-2zeah9lqneb4XXXXXXXX',
policy: 'accept',
ipProtocol: 'tcp',
portRange: '5004/5004',
});
// Create a RuntimeOptions instance and specify runtime parameters.
const runtime = new $Util.RuntimeOptions({
// Specify whether to disable certificate verification. A value of true specifies to disable certificate verification. A value of false specifies to enable certificate verification. Default value: false.
ignoreSSL: true,
});
const resp = await client.modifySecurityGroupRuleWithOptions(request, runtime);
console.log(resp.headers);
console.log(resp.body);
}
}
Client.main();
JavaScript:
const { default: Ecs20140526, ModifySecurityGroupRuleRequest } = require('@alicloud/ecs20140526');
const { Config } = require('@alicloud/openapi-client');
const { RuntimeOptions } = require('@alicloud/tea-util');
const { default: Credential } = require('@alicloud/credentials');
async function main() {
// The default credential.
const cred = new Credential();
const config = new Config({
credential: cred,
// The endpoint of an Alibaba Cloud service.
endpoint: 'ecs.cn-beijing.aliyuncs.com',
protocol: 'https',
});
const client = new Ecs20140526(config);
const request = new ModifySecurityGroupRuleRequest({
regionId: 'cn-beijing',
securityGroupId: 'sg-2zec0dm6qi66XXXXXXXX',
securityGroupRuleId: 'sgr-2zeah9lqneb4XXXXXXXX',
policy: 'accept',
ipProtocol: 'tcp',
portRange: '5004/5004',
});
// Create a RuntimeOptions instance and specify runtime parameters.
const runtime = new RuntimeOptions({
// Specify whether to disable certificate verification. A value of true specifies to disable certificate verification. A value of false specifies to enable certificate verification. Default value: false.
ignoreSSL: true,
});
const resp = await client.modifySecurityGroupRuleWithOptions(request, runtime);
console.log(resp.headers);
console.log(resp.body);
}
main();