VPC訪問
本文介紹用戶如何在自己的VPC內(nèi)訪問TPP服務。TPP會自動為您的VPC建立私網(wǎng)連接Privatelink,讓您可以在自己的VPC內(nèi)訪問TPP服務。注意:VPC內(nèi)訪問TPP服務是非常安全的,它隔離了公網(wǎng)、其它專有網(wǎng)絡,如果您想在公網(wǎng)訪問請參考文檔公網(wǎng)調(diào)試。
網(wǎng)絡結構
TPP會自動為您的VPC建立私網(wǎng)連接Privatelink,讓您可以在自己的VPC內(nèi)訪問TPP云服務。
您會使用到【VPC訪問域名】(即Privatelink連接提供的終端節(jié)點域名),來訪問TPP云服務。
前置條件
詳情請參考使用流程
您已經(jīng)成功購買了TPP實例
并將方案代碼發(fā)布到正式環(huán)境
創(chuàng)建并發(fā)布好場景實驗
協(xié)議
協(xié)議 | 方法 | 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
參數(shù)名 | 參數(shù)值 | 說明 |
_input_charset | UTF-8 | 必須輸入編碼 |
_output_charset | UTF-8 | 必須輸出編碼 |
_instance_cluster | 實例id | 必須 |
appid | 場景id | 必須 |
參數(shù)名 | 參數(shù)值 | 說明 |
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));