# [Cloud](/miniprogram/dev/wxcloudservice/wxcloud/reference-sdk-api/Cloud).callContainer(options: Object): Promise<Object>

> 支持端：[小程序 2.13.1](/miniprogram/dev/framework/client-lib/version.md), [Web 1.1.0](/miniprogram/dev/wxcloudservice/wxcloud/reference/changelog-web-sdk)

调用云托管服务

## 参数

### options: Object

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 |
| ---- | ---- | ------ | -------- | ---- |
| path | string |  | 是 | 服务路径 |
| method | string | GET | 否 | HTTP 请求方法 |
| data | string/Object/ArrayBuffer |  | 否 | 请求数据 |
| header | Object |  | 否 | 设置请求的 header，header 中不能设置 Referer。content-type 默认为 application/json |
| timeout | number |  | 否 | 根据业务自定义超时时间，单位为毫秒，本项取值需要小于 1500 毫秒（服务启动耗时 ＋请求耗时 < timeout < 1500 毫秒） |
| dataType | string | json | 否 | 返回的数据格式 |
| responseType | string | text | 否 | 响应的数据类型 |

## 返回值

### Promise.<Object>

| 属性 | 类型 | 说明 |
| ---- | ---- | ---- |
| data  | string/Object/ArrayBuffer | 开发者云托管服务返回的数据 |
| statusCode  | number | 开发者云托管服务返回的 HTTP 状态码 |
| header  | Object | 开发者云托管返回的 HTTP Response Header |
| cookies  | Object | 开发者云托管返回的 cookies，格式为字符串数组，仅小程序端有此字段 |

## 小程序端 & Web 端示例

以下为小程序端示例，对于 Web 端，只需将 wx.cloud 改为 cloud 即可。

Promise 风格
```js
// 容器调用必填环境id，不能为空
var c1 = new wx.cloud.Cloud({
  resourceEnv: '环境id'
})
await c1.init()

const r = await c1.callContainer({
  path: '/xxx', // 填入业务自定义路径
  header: {
    'X-WX-SERVICE': 'xxx', // 填入服务名称
  },
  // 其余参数同 wx.request
  method: 'POST',
})
console.log(r)
```

Callback 风格
```js
// 容器调用必填环境id，不能为空
var c1 = new wx.cloud.Cloud({
  resourceEnv: '环境id'
})
await c1.init()

c1.callContainer({
  path: '/xxx', // 填入业务自定义路径
  header: {
    'X-WX-SERVICE': 'xxx', // 填入服务名称
  },
  // 其余参数同 wx.request
  method: 'POST',
  success: console.log,
  fail: console.error,
})
```
