# 其他客户端-访问云托管服务

各种语言和框架的网络请求,请参阅各语言的文档和其他教学资料。在这里我们只列举一些常见的服务端和客户端调用。

# 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);
    }
});