@@ -135,6 +135,52 @@ after 类 Hook 的 `func` 签名:`function(request: Request)`。
135135
136136这些 Hook 需要用 `AV.Cloud.define` 来定义,详见文档 [实时通信概览:云引擎 Hook](https:// leancloud.cn/docs/realtime_v2.html#云引擎_Hook)
137137
138+ ### AV.Cloud.httpRequest
139+
140+ 注意:该 API 已不再维护且可能在之后的版本中去除,请使用 [request](https:// www.npmjs.com/package/request) 发起 HTTP 请求!
141+
142+ ```javascript
143+ AV.Cloud.httpRequest(options: object);
144+ ```
145+
146+ options 的属性包括:
147+
148+ * `url`:被请求的 Url, 例如 `https:// api.leancloud.cn/1.1/ping`。
149+ * `success: function(response: Response)`:成功回调,接受一个 HTTP 响应作为参数。
150+ * `error: function(response: Response)`:失败回调,接受一个 HTTP 响应作为参数。
151+ * `method: string`:HTTP 方法,默认为 `GET`。
152+ * `params`:Query String,可以是对象 `{q : ' Sean Plott' }` 也可以是字符串 ` q= Sean Plott` 。
153+ * ` headers: object` :HTTP 头,例如 ` {' Content-Type' : ' application/json' }` 。
154+ * ` body: object` :HTTP 请求正文,默认使用 urlencode 编码,如果指定了 ` Content- Type` 为 ` application/ json` 则发送 JSON 格式的正文;不适用于 ` GET ` 或 ` HEAD ` 请求。
155+ * ` timeout: number` :超时时间,单位秒,默认 ` 10000 ` 。
156+
157+ Response 的属性包括:
158+
159+ * ` status: number` :HTTP 响应状态码。
160+ * ` headers: object` :HTTP 响应头。
161+ * ` text: string` :HTTP 响应正文。
162+ * ` buffer: Buffer` :HTTP 响应正文。
163+ * ` data` 解析后的 HTTP 响应正文,例如对于 ` Content- Type` 为 ` application/ json` 时,会将响应正文解析为一个对象。
164+
165+ 示例:
166+
167+ ` ` ` javascript
168+ AV .Cloud .httpRequest ({
169+ method: ' POST' ,
170+ url: ' http://www.example.com/create_post' ,
171+ body: {
172+ title: ' Vote for Pedro' ,
173+ body: ' If you vote for Pedro, your wildest dreams will come true'
174+ },
175+ success : function (httpResponse ) {
176+ console .log (httpResponse .text );
177+ },
178+ error : function (httpResponse ) {
179+ console .error (' Request failed with response code ' + httpResponse .status );
180+ }
181+ });
182+ ` ` `
183+
138184## Middlewares
139185
140186### cookie-session
0 commit comments