本文介绍用户如何在自己的VPC内访问TPP服务。TPP会自动为您的VPC建立私网连接Privatelink,让您可以在自己的VPC内访问TPP服务。注意:VPC内访问TPP服务是非常安全的,它隔离了公网、其它专有网络,如果您想在公网访问请参考文档公网调试。
网络结构
TPP会自动为您的VPC建立私网连接Privatelink,让您可以在自己的VPC内访问TPP云服务。
您会使用到【VPC访问域名】(即Privatelink连接提供的终端节点域名),来访问TPP云服务。
前置条件
详情请参考使用流程
您已经成功购买了TPP实例
并将方案代码发布到正式环境
创建并发布好场景实验
协议
协议 | 方法 | demo |
HTTP | GET | http://${domain}/recommend?_input_charset=UTF-8&_output_charset=UTF-8&_instance_cluster=${instanceId}&appid=${sceneId}&yourRequestParam= |
HTTP | POST (推荐) |
http://${domain}/recommend?
"Content-Type:application/x-www-form-urlencoded"
_instance_cluster=${instanceId}&appid=${sceneId}&yourRequestParam= |
实例详情->服务访问信息->VPC访问域名
/recommend
参数名 | 参数值 | 说明 |
_input_charset | UTF-8 | 必须输入编码 |
_output_charset | UTF-8 | 必须输出编码 |
_instance_cluster | 实例id | 必须 |
appid | 场景id | 必须 |
参数名 | 参数值 | 说明 |
userId | 例如:123456789 | 用户id |
…… |
返回结果
2022-03-28 1.0 开源版本
各语言示例
GET
curl -i "http://${domain}/recommend?_input_charset=UTF-8&_output_charset=UTF-8&_instance_cluster=${instanceId}&appid=${sceneId}&yourRequestParam="
POST
curl --location --request POST 'http://${domain}/recommend' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '_input_charset=UTF-8' \
--data-urlencode '_output_charset=UTF-8' \
--data-urlencode '_instance_cluster=${instanceId}' \
--data-urlencode 'appid=${sceneId}' \
--data-urlencode 'yourRequestParam=${yourRequestParam}'
GET
OkHttpClient client = new OkHttpClient().newBuilder().build();
Request request = new Request.Builder()
.url("http://${domain}/recommend?_input_charset=UTF-8&_output_charset=UTF-8&_instance_cluster=${instanceId}&appid=${sceneId}&yourRequestParam=")
.method("GET",null)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
POST
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "_input_charset=UTF-8&_output_charset=UTF-8&_instance_cluster=${instanceId}&appid=${sceneId}&yourRequestParam=${yourRequestParam}");
Request request = new Request.Builder()
.url("http://${domain}/recommend?")
.method("POST", body)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
GET
var myHeaders = new Headers();
var urlencoded = new URLSearchParams();
var requestOptions = {
method: 'GET',
headers: myHeaders,
body: urlencoded};
fetch("http://${domain}/recommend?_input_charset=UTF-8&_output_charset=UTF-8&_instance_cluster=${instanceId}&appid=${sceneId}&yourRequestParam=", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
POST
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
var urlencoded = new URLSearchParams();
urlencoded.append("_input_charset", "UTF-8");
urlencoded.append("_output_charset", "UTF-8");
urlencoded.append("_instance_cluster", "${instanceId}");
urlencoded.append("appid", "${sceneId}");
urlencoded.append("yourRequestParam", "${yourRequestParam}");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};
fetch("http://${domain}/recommend", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));