基础API
http

OneScript 内置了网络请求库Axios (opens in a new tab),您可以查看Axios官方文档 (opens in a new tab)来了解更多用法

发送一个 GET 请求

const axios = require('axios');
 
// 向给定ID的用户发起请求
axios.get('https://api.restful-api.dev/objects')
  .then(function (response) {
    // 处理成功情况
    console.log(response.data);
  })
  .catch(function (error) {
    // 处理错误情况
    console.log(error);
  })
  .finally(function () {
    // 总是会执行
  });

发送一个 POST 请求

const axios = require('axios');
 
axios.post('https://api.restful-api.dev/objects', {
  name: 'Apple MacBook Pro 16',
  data: {
    year: 2019,
    price: 1849.99,
    'CPU model': 'Intel Core i7',
    'Hard disk size': '512GB'
  }
})
  .then(function (response) {
    console.log(response.data);
  })
  .catch(function (error) {
    console.log(error);
  });