提交 1d7caf5b 编写于 作者: 雪洛's avatar 雪洛

docs: update get http info

上级 050f9038
......@@ -400,12 +400,72 @@ module.exports = {
```js
module.exports = {
_before: function() { // _before的用法请看后续章节
const params = this.getHttpInfo() // 返回值和云函数url化时的event一致
const httpInfo = this.getHttpInfo()
}
}
```
相关文档:[云函数url化的入参](cf-functions.md#input)
httpInfo为集成请求格式的对象,结构如下
```js
{
path: 'HTTP请求路径,如 /hello',
httpMethod: 'HTTP请求方法,如 GET',
headers: {HTTP请求头},
queryStringParameters: {HTTP请求的Query键值对形式},
body: 'HTTP请求体',
isBase64Encoded: 'true or false,表示body是否为Base64编码'
}
```
**注意**
- httpInfo.path表示以配置的url化路径为根路径的访问路径。以配置`/test`为云对象url化路径,访问`/test/a/b/c`时path为`/a/b/c`
**示例**
使用GET请求`https://${云对象Url化域名}/${触发路径}/${云对象方法名}?a=1&b=2`,云对象接收到的`event`
```js
{
path: '/${云对象方法名}',
httpMethod: 'GET',
headers: {HTTP请求头},
queryStringParameters: {a: "1", b: "2"},
isBase64Encoded: false
}
```
使用POST请求`https://${云对象Url化域名}/${触发路径}/${云对象方法名}`,云对象接收到的`event.body`为请求发送的数据,**uni.request默认content-type为application/json**
```js
// 以uni.request为例
uni.request({
method: 'POST',
url: 'https://${云对象Url化域名}/${触发路径}/${云对象方法名}',
data: {
a: 1,
b: 2
},
success(res) {
console.log(res);
}
})
// 云对象的httpInfo
{
path: '/${云对象方法名}',
httpMethod: 'POST',
headers: {
...
"content-type": 'application/json'
},
isBase64Encoded: false,
body: '{"a":1,"b":2}', // 注意此处可能是base64,需要根据isBase64Encoded判断
}
```
## 内置特殊方法@before-and-after
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册