通过 HTTPS 访问
创建云托管服务之后, 云托管会为您提供该服务的 HTTPS 访问域名。您可以通过该域名,来访问您部署的服务。
所有的云托管服务都会提供一个 HTTPS 网址,该网址表示服务的默认 HTTPS 端点,不过正式环境场景下,我们强烈建议您配置自定义自定义域名
部分应用场景包括:
- 自定义 RESTFul Web API
- 专用微服务
- web 应用
创建服务
在云托管上创建服务需要满足以下条件:
- 通过公共互联网访问
- 供公众使用的网址
云托管默认为用户提供公共互联网访问,且默认域名不会有任何的鉴权操作,如需关闭公网域名访问,请在部署服务之后,在服务设置
-> 网络访问
中关闭公网开关。
服务域名
公网域名
云托管会为每个服务分配一个公网域名,您可以通过该域名访问您的云托管服务。您也可以在 服务设置
-> 网络访问
中关闭公网开关。
内网域名
云托管也会为每个服务分配一个内网域名,该内网域名默认是关闭状态。您可以在 服务设置
-> 网络访问
中开启公网开关。
内网域名有以下场景:
- 服务之间通过 HTTP 相互访问
- 复制直接通过 gRPC 相互访问
- 服务间通过其它4层协议相互访问等等
我们假设创建的服务默认域名为: https://demo.ap-shanghai.run.tcloudbase.com
通过 CURL 访问
curl --location --request GET 'https://demo.ap-shanghai.run.tcloudbase.com'
通过 PHP-CURL 访问
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://demo.ap-shanghai.run.tcloudbase.com',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
通过 Node.js
var requestOptions = {
method: 'GET',
redirect: 'follow'
};
fetch("https://demo.ap-shanghai.run.tcloudbase.com", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
通过浏览器 JS-XHR 访问
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://demo.ap-shanghai.run.tcloudbase.com");
xhr.send();
通过QQ小程序访问
qq.request({
url: 'https://demo.ap-shanghai.run.tcloudbase.com',
success(res) {
console.log(res.data)
}
})
通过 UNI-APP 访问
uni.request({
url: 'https://demo.ap-shanghai.run.tcloudbase.com',
success: function(res) {
console.log(res.data);
}
});