axios-miniprogram/docs/pages/request/CONNECT.md

52 lines
1.0 KiB
Markdown
Raw Normal View History

2023-04-14 16:38:25 +08:00
---
title: CONNECT 请求
---
# {{ $frontmatter.title }}
::: tip {{ $frontmatter.title }}
在 HTTP 协议中CONNECT 方法可以开启一个客户端与所请求资源之间的双向沟通的通道。它可以用来创建隧道tunnel
:::
## 普通的 `CONNECT` 请求
2023-04-15 16:21:54 +08:00
可以传递第一个参数 `url` 发送 `CONNECT` 请求。
2023-04-14 16:38:25 +08:00
```ts
import axios from 'axios-miniprogram';
axios
.connect('https://api.com/test')
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
// 失败之后做些什么
});
```
2023-04-15 16:21:54 +08:00
## 携带请求配置的 `CONNECT` 请求
2023-04-14 16:38:25 +08:00
2023-04-15 16:21:54 +08:00
也可以额外传递第二个参数 `config` 发送携带请求配置的 `CONNECT` 请求。
2023-04-14 16:38:25 +08:00
```ts
import axios from 'axios-miniprogram';
axios
.connect('https://api.com/test', {
headers: {
Connection: 'Keep-Alive',
},
})
.then((response) => {
// 成功之后做些什么
})
.catch((error) => {
// 失败之后做些什么
});
```
## 兼容性
<VPCompatibility wx swan='仅 Android 支持' tt='1.0.0' qq />