• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import type { AsyncCallback, Callback } from './@ohos.base';
17import type connection from './@ohos.net.connection';
18
19/**
20 * Provides http related APIs.
21 * @namespace http
22 * @syscap SystemCapability.Communication.NetStack
23 * @since 6
24 */
25/**
26 * Provides http related APIs.
27 * @namespace http
28 * @syscap SystemCapability.Communication.NetStack
29 * @crossplatform
30 * @since 10
31 */
32declare namespace http {
33  /**
34   * @syscap SystemCapability.Communication.NetStack
35   * @since 10
36   */
37  type HttpProxy = connection.HttpProxy;
38
39  /**
40   * Creates an HTTP request task.
41   * @returns { HttpRequest } the HttpRequest of the createHttp.
42   * @syscap SystemCapability.Communication.NetStack
43   * @since 6
44   */
45  /**
46   * Creates an HTTP request task.
47   * @returns { HttpRequest } the HttpRequest of the createHttp.
48   * @syscap SystemCapability.Communication.NetStack
49   * @crossplatform
50   * @since 10
51   */
52  function createHttp(): HttpRequest;
53
54  /**
55   * Specifies the type and value range of the optional parameters in the HTTP request.
56   * @interface HttpRequestOptions
57   * @syscap SystemCapability.Communication.NetStack
58   * @since 6
59   */
60  /**
61   * Specifies the type and value range of the optional parameters in the HTTP request.
62   * @interface HttpRequestOptions
63   * @syscap SystemCapability.Communication.NetStack
64   * @crossplatform
65   * @since 10
66   */
67  export interface HttpRequestOptions {
68    /**
69     * Request method,default is GET.
70     * @type {?RequestMethod}
71     * @syscap SystemCapability.Communication.NetStack
72     * @since 6
73     */
74    /**
75     * Request method,default is GET.
76     * @type {?RequestMethod}
77     * @syscap SystemCapability.Communication.NetStack
78     * @crossplatform
79     * @since 10
80     */
81    method?: RequestMethod;
82
83    /**
84     * Additional data of the request.
85     * extraData can be a string or an Object (API 6) or an ArrayBuffer(API 8).
86     * @type {?string | Object | ArrayBuffer}
87     * @syscap SystemCapability.Communication.NetStack
88     * @since 6
89     */
90    /**
91     * Additional data of the request.
92     * extraData can be a string or an Object (API 6) or an ArrayBuffer(API 8).
93     * @type {?string | Object | ArrayBuffer}
94     * @syscap SystemCapability.Communication.NetStack
95     * @crossplatform
96     * @since 10
97     */
98    extraData?: string | Object | ArrayBuffer;
99
100    /**
101     * Data type to be returned. If this parameter is set, the system preferentially returns the specified type.
102     * @type {?HttpDataType}
103     * @syscap SystemCapability.Communication.NetStack
104     * @since 9
105     */
106    /**
107     * Data type to be returned. If this parameter is set, the system preferentially returns the specified type.
108     * @type {?HttpDataType}
109     * @syscap SystemCapability.Communication.NetStack
110     * @crossplatform
111     * @since 10
112     */
113    expectDataType?: HttpDataType;
114
115    /**
116     * default is true
117     * @type {?boolean}
118     * @syscap SystemCapability.Communication.NetStack
119     * @since 9
120     */
121    /**
122     * default is true
123     * @type {?boolean}
124     * @syscap SystemCapability.Communication.NetStack
125     * @crossplatform
126     * @since 10
127     */
128    usingCache?: boolean;
129
130    /**
131     * [1, 1000], default is 1.
132     * @type {?number}
133     * @syscap SystemCapability.Communication.NetStack
134     * @since 9
135     */
136    /**
137     * [1, 1000], default is 1.
138     * @type {?number}
139     * @syscap SystemCapability.Communication.NetStack
140     * @crossplatform
141     * @since 10
142     */
143    priority?: number;
144
145    /**
146     * HTTP request header. default is 'content-type': 'application/json'
147     * @type {?Object}
148     * @syscap SystemCapability.Communication.NetStack
149     * @since 6
150     */
151    /**
152     * HTTP request header. default is 'content-type': 'application/json'
153     * @type {?Object}
154     * @syscap SystemCapability.Communication.NetStack
155     * @crossplatform
156     * @since 10
157     */
158    header?: Object;
159
160    /**
161     * Read timeout period. The default value is 60,000, in ms.
162     * @type {?number}
163     * @syscap SystemCapability.Communication.NetStack
164     * @since 6
165     */
166    /**
167     * Read timeout period. The default value is 60,000, in ms.
168     * @type {?number}
169     * @syscap SystemCapability.Communication.NetStack
170     * @crossplatform
171     * @since 10
172     */
173    readTimeout?: number;
174
175    /**
176     * Connection timeout interval. The default value is 60,000, in ms.
177     * @type {?number}
178     * @syscap SystemCapability.Communication.NetStack
179     * @since 6
180     */
181    /**
182     * Connection timeout interval. The default value is 60,000, in ms.
183     * @type {?number}
184     * @syscap SystemCapability.Communication.NetStack
185     * @crossplatform
186     * @since 10
187     */
188    connectTimeout?: number;
189
190    /**
191     * default is automatically specified by the system.
192     * @type {?HttpProtocol}
193     * @syscap SystemCapability.Communication.NetStack
194     * @since 9
195     */
196    /**
197     * default is automatically specified by the system.
198     * @type {?HttpProtocol}
199     * @syscap SystemCapability.Communication.NetStack
200     * @crossplatform
201     * @since 10
202     */
203    usingProtocol?: HttpProtocol;
204    /**
205     * If this parameter is set as type of boolean, the system will use default proxy or not use proxy.
206     * If this parameter is set as type of HttpProxy, the system will use the specified HttpProxy.
207     * @type {?boolean | HttpProxy}
208     * @syscap SystemCapability.Communication.NetStack
209     * @since 10
210     */
211    usingProxy?: boolean | HttpProxy;
212
213    /**
214     * If this parameter is set, the system will use ca path specified by user, or else use preset ca by the system.
215     * @type {?string}
216     * @syscap SystemCapability.Communication.NetStack
217     * @since 10
218     */
219    caPath?: string;
220  }
221
222  /**
223   * <p>Defines an HTTP request task. Before invoking APIs provided by HttpRequest,
224   * you must call createHttp() to create an HttpRequestTask object.</p>
225   * @interface HttpRequest
226   * @syscap SystemCapability.Communication.NetStack
227   * @since 6
228   */
229  /**
230   * <p>Defines an HTTP request task. Before invoking APIs provided by HttpRequest,
231   * you must call createHttp() to create an HttpRequestTask object.</p>
232   * @interface HttpRequest
233   * @syscap SystemCapability.Communication.NetStack
234   * @crossplatform
235   * @since 10
236   */
237  export interface HttpRequest {
238    /**
239     * Initiates an HTTP request to a given URL.
240     * @permission ohos.permission.INTERNET
241     * @param { string } url - URL for initiating an HTTP request.
242     * @param { AsyncCallback<HttpResponse> } callback - the callback of request.
243     * @throws { BusinessError } 401 - Parameter error.
244     * @throws { BusinessError } 201 - Permission denied.
245     * @throws { BusinessError } 2300001 - Unsupported protocol.
246     * @throws { BusinessError } 2300003 - URL using bad/illegal format or missing URL.
247     * @throws { BusinessError } 2300005 - Couldn't resolve proxy name.
248     * @throws { BusinessError } 2300006 - Couldn't resolve host name.
249     * @throws { BusinessError } 2300007 - Couldn't connect to server.
250     * @throws { BusinessError } 2300008 - Weird server reply.
251     * @throws { BusinessError } 2300009 - Access denied to remote resource.
252     * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer.
253     * @throws { BusinessError } 2300018 - Transferred a partial file.
254     * @throws { BusinessError } 2300023 - Failed writing received data to disk/application.
255     * @throws { BusinessError } 2300025 - Upload failed.
256     * @throws { BusinessError } 2300026 - Failed to open/read local data from file/application.
257     * @throws { BusinessError } 2300027 - Out of memory.
258     * @throws { BusinessError } 2300028 - Timeout was reached.
259     * @throws { BusinessError } 2300047 - Number of redirects hit maximum amount.
260     * @throws { BusinessError } 2300052 - Server returned nothing (no headers, no data).
261     * @throws { BusinessError } 2300055 - Failed sending data to the peer.
262     * @throws { BusinessError } 2300056 - Failure when receiving data from the peer.
263     * @throws { BusinessError } 2300058 - Problem with the local SSL certificate.
264     * @throws { BusinessError } 2300059 - Couldn't use specified SSL cipher.
265     * @throws { BusinessError } 2300060 - SSL peer certificate or SSH remote key was not OK.
266     * @throws { BusinessError } 2300061 - Unrecognized or bad HTTP Content or Transfer-Encoding.
267     * @throws { BusinessError } 2300063 - Maximum file size exceeded.
268     * @throws { BusinessError } 2300070 - Disk full or allocation exceeded.
269     * @throws { BusinessError } 2300073 - Remote file already exists.
270     * @throws { BusinessError } 2300077 - Problem with the SSL CA cert (path? access rights?).
271     * @throws { BusinessError } 2300078 - Remote file not found.
272     * @throws { BusinessError } 2300094 - An authentication function returned an error.
273     * @throws { BusinessError } 2300999 - Unknown Other Error.
274     * @syscap SystemCapability.Communication.NetStack
275     * @since 6
276     */
277    /**
278     * Initiates an HTTP request to a given URL.
279     * @permission ohos.permission.INTERNET
280     * @param { string } url - URL for initiating an HTTP request.
281     * @param { AsyncCallback<HttpResponse> } callback - the callback of request.
282     * @throws { BusinessError } 401 - Parameter error.
283     * @throws { BusinessError } 201 - Permission denied.
284     * @throws { BusinessError } 2300001 - Unsupported protocol.
285     * @throws { BusinessError } 2300003 - URL using bad/illegal format or missing URL.
286     * @throws { BusinessError } 2300005 - Couldn't resolve proxy name.
287     * @throws { BusinessError } 2300006 - Couldn't resolve host name.
288     * @throws { BusinessError } 2300007 - Couldn't connect to server.
289     * @throws { BusinessError } 2300008 - Weird server reply.
290     * @throws { BusinessError } 2300009 - Access denied to remote resource.
291     * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer.
292     * @throws { BusinessError } 2300018 - Transferred a partial file.
293     * @throws { BusinessError } 2300023 - Failed writing received data to disk/application.
294     * @throws { BusinessError } 2300025 - Upload failed.
295     * @throws { BusinessError } 2300026 - Failed to open/read local data from file/application.
296     * @throws { BusinessError } 2300027 - Out of memory.
297     * @throws { BusinessError } 2300028 - Timeout was reached.
298     * @throws { BusinessError } 2300047 - Number of redirects hit maximum amount.
299     * @throws { BusinessError } 2300052 - Server returned nothing (no headers, no data).
300     * @throws { BusinessError } 2300055 - Failed sending data to the peer.
301     * @throws { BusinessError } 2300056 - Failure when receiving data from the peer.
302     * @throws { BusinessError } 2300058 - Problem with the local SSL certificate.
303     * @throws { BusinessError } 2300059 - Couldn't use specified SSL cipher.
304     * @throws { BusinessError } 2300060 - SSL peer certificate or SSH remote key was not OK.
305     * @throws { BusinessError } 2300061 - Unrecognized or bad HTTP Content or Transfer-Encoding.
306     * @throws { BusinessError } 2300063 - Maximum file size exceeded.
307     * @throws { BusinessError } 2300070 - Disk full or allocation exceeded.
308     * @throws { BusinessError } 2300073 - Remote file already exists.
309     * @throws { BusinessError } 2300077 - Problem with the SSL CA cert (path? access rights?).
310     * @throws { BusinessError } 2300078 - Remote file not found.
311     * @throws { BusinessError } 2300094 - An authentication function returned an error.
312     * @throws { BusinessError } 2300999 - Unknown Other Error.
313     * @syscap SystemCapability.Communication.NetStack
314     * @crossplatform
315     * @since 10
316     */
317    request(url: string, callback: AsyncCallback<HttpResponse>): void;
318
319    /**
320     * Initiates an HTTP request to a given URL.
321     * @permission ohos.permission.INTERNET
322     * @param { string } url - URL for initiating an HTTP request.
323     * @param { HttpRequestOptions } options - Optional parameters {@link HttpRequestOptions}.
324     * @param { AsyncCallback<HttpResponse> } callback - the callback of request..
325     * @throws { BusinessError } 401 - Parameter error.
326     * @throws { BusinessError } 201 - Permission denied.
327     * @throws { BusinessError } 2300001 - Unsupported protocol.
328     * @throws { BusinessError } 2300003 - URL using bad/illegal format or missing URL.
329     * @throws { BusinessError } 2300005 - Couldn't resolve proxy name.
330     * @throws { BusinessError } 2300006 - Couldn't resolve host name.
331     * @throws { BusinessError } 2300007 - Couldn't connect to server.
332     * @throws { BusinessError } 2300008 - Weird server reply.
333     * @throws { BusinessError } 2300009 - Access denied to remote resource.
334     * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer.
335     * @throws { BusinessError } 2300018 - Transferred a partial file.
336     * @throws { BusinessError } 2300023 - Failed writing received data to disk/application.
337     * @throws { BusinessError } 2300025 - Upload failed.
338     * @throws { BusinessError } 2300026 - Failed to open/read local data from file/application.
339     * @throws { BusinessError } 2300027 - Out of memory.
340     * @throws { BusinessError } 2300028 - Timeout was reached.
341     * @throws { BusinessError } 2300047 - Number of redirects hit maximum amount.
342     * @throws { BusinessError } 2300052 - Server returned nothing (no headers, no data).
343     * @throws { BusinessError } 2300055 - Failed sending data to the peer.
344     * @throws { BusinessError } 2300056 - Failure when receiving data from the peer.
345     * @throws { BusinessError } 2300058 - Problem with the local SSL certificate.
346     * @throws { BusinessError } 2300059 - Couldn't use specified SSL cipher.
347     * @throws { BusinessError } 2300060 - SSL peer certificate or SSH remote key was not OK.
348     * @throws { BusinessError } 2300061 - Unrecognized or bad HTTP Content or Transfer-Encoding.
349     * @throws { BusinessError } 2300063 - Maximum file size exceeded.
350     * @throws { BusinessError } 2300070 - Disk full or allocation exceeded.
351     * @throws { BusinessError } 2300073 - Remote file already exists.
352     * @throws { BusinessError } 2300077 - Problem with the SSL CA cert (path? access rights?).
353     * @throws { BusinessError } 2300078 - Remote file not found.
354     * @throws { BusinessError } 2300094 - An authentication function returned an error.
355     * @throws { BusinessError } 2300999 - Unknown Other Error.
356     * @syscap SystemCapability.Communication.NetStack
357     * @since 6
358     */
359    /**
360     * Initiates an HTTP request to a given URL.
361     * @permission ohos.permission.INTERNET
362     * @param { string } url - URL for initiating an HTTP request.
363     * @param { HttpRequestOptions } options - Optional parameters {@link HttpRequestOptions}.
364     * @param { AsyncCallback<HttpResponse> } callback - the callback of request.
365     * @throws { BusinessError } 401 - Parameter error.
366     * @throws { BusinessError } 201 - Permission denied.
367     * @throws { BusinessError } 2300001 - Unsupported protocol.
368     * @throws { BusinessError } 2300003 - URL using bad/illegal format or missing URL.
369     * @throws { BusinessError } 2300005 - Couldn't resolve proxy name.
370     * @throws { BusinessError } 2300006 - Couldn't resolve host name.
371     * @throws { BusinessError } 2300007 - Couldn't connect to server.
372     * @throws { BusinessError } 2300008 - Weird server reply.
373     * @throws { BusinessError } 2300009 - Access denied to remote resource.
374     * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer.
375     * @throws { BusinessError } 2300018 - Transferred a partial file.
376     * @throws { BusinessError } 2300023 - Failed writing received data to disk/application.
377     * @throws { BusinessError } 2300025 - Upload failed.
378     * @throws { BusinessError } 2300026 - Failed to open/read local data from file/application.
379     * @throws { BusinessError } 2300027 - Out of memory.
380     * @throws { BusinessError } 2300028 - Timeout was reached.
381     * @throws { BusinessError } 2300047 - Number of redirects hit maximum amount.
382     * @throws { BusinessError } 2300052 - Server returned nothing (no headers, no data).
383     * @throws { BusinessError } 2300055 - Failed sending data to the peer.
384     * @throws { BusinessError } 2300056 - Failure when receiving data from the peer.
385     * @throws { BusinessError } 2300058 - Problem with the local SSL certificate.
386     * @throws { BusinessError } 2300059 - Couldn't use specified SSL cipher.
387     * @throws { BusinessError } 2300060 - SSL peer certificate or SSH remote key was not OK.
388     * @throws { BusinessError } 2300061 - Unrecognized or bad HTTP Content or Transfer-Encoding.
389     * @throws { BusinessError } 2300063 - Maximum file size exceeded.
390     * @throws { BusinessError } 2300070 - Disk full or allocation exceeded.
391     * @throws { BusinessError } 2300073 - Remote file already exists.
392     * @throws { BusinessError } 2300077 - Problem with the SSL CA cert (path? access rights?).
393     * @throws { BusinessError } 2300078 - Remote file not found.
394     * @throws { BusinessError } 2300094 - An authentication function returned an error.
395     * @throws { BusinessError } 2300999 - Unknown Other Error.
396     * @syscap SystemCapability.Communication.NetStack
397     * @crossplatform
398     * @since 10
399     */
400    request(url: string, options: HttpRequestOptions, callback: AsyncCallback<HttpResponse>): void;
401
402    /**
403     * Initiates an HTTP request to a given URL.
404     * @permission ohos.permission.INTERNET
405     * @param { string } url - URL for initiating an HTTP request.
406     * @param { HttpRequestOptions } options - Optional parameters {@link HttpRequestOptions}.
407     * @returns { Promise<HttpResponse> } The promise returned by the function.
408     * @throws { BusinessError } 401 - Parameter error.
409     * @throws { BusinessError } 201 - Permission denied.
410     * @throws { BusinessError } 2300001 - Unsupported protocol.
411     * @throws { BusinessError } 2300003 - URL using bad/illegal format or missing URL.
412     * @throws { BusinessError } 2300005 - Couldn't resolve proxy name.
413     * @throws { BusinessError } 2300006 - Couldn't resolve host name.
414     * @throws { BusinessError } 2300007 - Couldn't connect to server.
415     * @throws { BusinessError } 2300008 - Weird server reply.
416     * @throws { BusinessError } 2300009 - Access denied to remote resource.
417     * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer.
418     * @throws { BusinessError } 2300018 - Transferred a partial file.
419     * @throws { BusinessError } 2300023 - Failed writing received data to disk/application.
420     * @throws { BusinessError } 2300025 - Upload failed.
421     * @throws { BusinessError } 2300026 - Failed to open/read local data from file/application.
422     * @throws { BusinessError } 2300027 - Out of memory.
423     * @throws { BusinessError } 2300028 - Timeout was reached.
424     * @throws { BusinessError } 2300047 - Number of redirects hit maximum amount.
425     * @throws { BusinessError } 2300052 - Server returned nothing (no headers, no data).
426     * @throws { BusinessError } 2300055 - Failed sending data to the peer.
427     * @throws { BusinessError } 2300056 - Failure when receiving data from the peer.
428     * @throws { BusinessError } 2300058 - Problem with the local SSL certificate.
429     * @throws { BusinessError } 2300059 - Couldn't use specified SSL cipher.
430     * @throws { BusinessError } 2300060 - SSL peer certificate or SSH remote key was not OK.
431     * @throws { BusinessError } 2300061 - Unrecognized or bad HTTP Content or Transfer-Encoding.
432     * @throws { BusinessError } 2300063 - Maximum file size exceeded.
433     * @throws { BusinessError } 2300070 - Disk full or allocation exceeded.
434     * @throws { BusinessError } 2300073 - Remote file already exists.
435     * @throws { BusinessError } 2300077 - Problem with the SSL CA cert (path? access rights?).
436     * @throws { BusinessError } 2300078 - Remote file not found.
437     * @throws { BusinessError } 2300094 - An authentication function returned an error.
438     * @throws { BusinessError } 2300999 - Unknown Other Error.
439     * @syscap SystemCapability.Communication.NetStack
440     * @since 6
441     */
442    /**
443     * Initiates an HTTP request to a given URL.
444     * @permission ohos.permission.INTERNET
445     * @param { string } url - URL for initiating an HTTP request.
446     * @param { HttpRequestOptions } options - Optional parameters {@link HttpRequestOptions}.
447     * @returns { Promise<HttpResponse> } The promise returned by the function.
448     * @throws { BusinessError } 401 - Parameter error.
449     * @throws { BusinessError } 201 - Permission denied.
450     * @throws { BusinessError } 2300001 - Unsupported protocol.
451     * @throws { BusinessError } 2300003 - URL using bad/illegal format or missing URL.
452     * @throws { BusinessError } 2300005 - Couldn't resolve proxy name.
453     * @throws { BusinessError } 2300006 - Couldn't resolve host name.
454     * @throws { BusinessError } 2300007 - Couldn't connect to server.
455     * @throws { BusinessError } 2300008 - Weird server reply.
456     * @throws { BusinessError } 2300009 - Access denied to remote resource.
457     * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer.
458     * @throws { BusinessError } 2300018 - Transferred a partial file.
459     * @throws { BusinessError } 2300023 - Failed writing received data to disk/application.
460     * @throws { BusinessError } 2300025 - Upload failed.
461     * @throws { BusinessError } 2300026 - Failed to open/read local data from file/application.
462     * @throws { BusinessError } 2300027 - Out of memory.
463     * @throws { BusinessError } 2300028 - Timeout was reached.
464     * @throws { BusinessError } 2300047 - Number of redirects hit maximum amount.
465     * @throws { BusinessError } 2300052 - Server returned nothing (no headers, no data).
466     * @throws { BusinessError } 2300055 - Failed sending data to the peer.
467     * @throws { BusinessError } 2300056 - Failure when receiving data from the peer.
468     * @throws { BusinessError } 2300058 - Problem with the local SSL certificate.
469     * @throws { BusinessError } 2300059 - Couldn't use specified SSL cipher.
470     * @throws { BusinessError } 2300060 - SSL peer certificate or SSH remote key was not OK.
471     * @throws { BusinessError } 2300061 - Unrecognized or bad HTTP Content or Transfer-Encoding.
472     * @throws { BusinessError } 2300063 - Maximum file size exceeded.
473     * @throws { BusinessError } 2300070 - Disk full or allocation exceeded.
474     * @throws { BusinessError } 2300073 - Remote file already exists.
475     * @throws { BusinessError } 2300077 - Problem with the SSL CA cert (path? access rights?).
476     * @throws { BusinessError } 2300078 - Remote file not found.
477     * @throws { BusinessError } 2300094 - An authentication function returned an error.
478     * @throws { BusinessError } 2300999 - Unknown Other Error.
479     * @syscap SystemCapability.Communication.NetStack
480     * @crossplatform
481     * @since 10
482     */
483    request(url: string, options?: HttpRequestOptions): Promise<HttpResponse>;
484
485    /**
486     * Initiates an HTTP request to a given URL, applicable to scenarios where http response supports streaming.
487     * @permission ohos.permission.INTERNET
488     * @param { string } url - URL for initiating an HTTP request.
489     * @param { AsyncCallback<number> } callback - Returns the callback of requestInStream {@link ResponseCode},
490     * should use on_headersReceive and on_dataReceive to get http response.
491     * @throws { BusinessError } 401 - Parameter error.
492     * @throws { BusinessError } 201 - Permission denied.
493     * @throws { BusinessError } 2300001 - Unsupported protocol.
494     * @throws { BusinessError } 2300003 - URL using bad/illegal format or missing URL.
495     * @throws { BusinessError } 2300005 - Couldn't resolve proxy name.
496     * @throws { BusinessError } 2300006 - Couldn't resolve host name.
497     * @throws { BusinessError } 2300007 - Couldn't connect to server.
498     * @throws { BusinessError } 2300008 - Weird server reply.
499     * @throws { BusinessError } 2300009 - Access denied to remote resource.
500     * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer.
501     * @throws { BusinessError } 2300018 - Transferred a partial file.
502     * @throws { BusinessError } 2300023 - Failed writing received data to disk/application.
503     * @throws { BusinessError } 2300025 - Upload failed.
504     * @throws { BusinessError } 2300026 - Failed to open/read local data from file/application.
505     * @throws { BusinessError } 2300027 - Out of memory.
506     * @throws { BusinessError } 2300028 - Timeout was reached.
507     * @throws { BusinessError } 2300047 - Number of redirects hit maximum amount.
508     * @throws { BusinessError } 2300052 - Server returned nothing (no headers, no data).
509     * @throws { BusinessError } 2300055 - Failed sending data to the peer.
510     * @throws { BusinessError } 2300056 - Failure when receiving data from the peer.
511     * @throws { BusinessError } 2300058 - Problem with the local SSL certificate.
512     * @throws { BusinessError } 2300059 - Couldn't use specified SSL cipher.
513     * @throws { BusinessError } 2300060 - SSL peer certificate or SSH remote key was not OK.
514     * @throws { BusinessError } 2300061 - Unrecognized or bad HTTP Content or Transfer-Encoding.
515     * @throws { BusinessError } 2300063 - Maximum file size exceeded.
516     * @throws { BusinessError } 2300070 - Disk full or allocation exceeded.
517     * @throws { BusinessError } 2300073 - Remote file already exists.
518     * @throws { BusinessError } 2300077 - Problem with the SSL CA cert (path? access rights?).
519     * @throws { BusinessError } 2300078 - Remote file not found.
520     * @throws { BusinessError } 2300094 - An authentication function returned an error.
521     * @throws { BusinessError } 2300999 - Unknown Other Error.
522     * @syscap SystemCapability.Communication.NetStack
523     * @since 10
524     */
525    requestInStream(url: string, callback: AsyncCallback<number>): void;
526
527    /**
528     * Initiates an HTTP request to a given URL, applicable to scenarios where http response supports streaming.
529     * @permission ohos.permission.INTERNET
530     * @param { string } url - URL for initiating an HTTP request.
531     * @param { HttpRequestOptions } options - Optional parameters {@link HttpRequestOptions}.
532     * @param { AsyncCallback<number> } callback - the callback of requestInStream.
533     * @throws { BusinessError } 401 - Parameter error.
534     * @throws { BusinessError } 201 - Permission denied.
535     * @throws { BusinessError } 2300001 - Unsupported protocol.
536     * @throws { BusinessError } 2300003 - URL using bad/illegal format or missing URL.
537     * @throws { BusinessError } 2300005 - Couldn't resolve proxy name.
538     * @throws { BusinessError } 2300006 - Couldn't resolve host name.
539     * @throws { BusinessError } 2300007 - Couldn't connect to server.
540     * @throws { BusinessError } 2300008 - Weird server reply.
541     * @throws { BusinessError } 2300009 - Access denied to remote resource.
542     * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer.
543     * @throws { BusinessError } 2300018 - Transferred a partial file.
544     * @throws { BusinessError } 2300023 - Failed writing received data to disk/application.
545     * @throws { BusinessError } 2300025 - Upload failed.
546     * @throws { BusinessError } 2300026 - Failed to open/read local data from file/application.
547     * @throws { BusinessError } 2300027 - Out of memory.
548     * @throws { BusinessError } 2300028 - Timeout was reached.
549     * @throws { BusinessError } 2300047 - Number of redirects hit maximum amount.
550     * @throws { BusinessError } 2300052 - Server returned nothing (no headers, no data).
551     * @throws { BusinessError } 2300055 - Failed sending data to the peer.
552     * @throws { BusinessError } 2300056 - Failure when receiving data from the peer.
553     * @throws { BusinessError } 2300058 - Problem with the local SSL certificate.
554     * @throws { BusinessError } 2300059 - Couldn't use specified SSL cipher.
555     * @throws { BusinessError } 2300060 - SSL peer certificate or SSH remote key was not OK.
556     * @throws { BusinessError } 2300061 - Unrecognized or bad HTTP Content or Transfer-Encoding.
557     * @throws { BusinessError } 2300063 - Maximum file size exceeded.
558     * @throws { BusinessError } 2300070 - Disk full or allocation exceeded.
559     * @throws { BusinessError } 2300073 - Remote file already exists.
560     * @throws { BusinessError } 2300077 - Problem with the SSL CA cert (path? access rights?).
561     * @throws { BusinessError } 2300078 - Remote file not found.
562     * @throws { BusinessError } 2300094 - An authentication function returned an error.
563     * @throws { BusinessError } 2300999 - Unknown Other Error.
564     * @syscap SystemCapability.Communication.NetStack
565     * @since 10
566     */
567    requestInStream(url: string, options: HttpRequestOptions, callback: AsyncCallback<number>): void;
568
569    /**
570     * Initiates an HTTP request to a given URL, applicable to scenarios where http response supports streaming.
571     * @permission ohos.permission.INTERNET
572     * @param { string } url - URL for initiating an HTTP request.
573     * @param { HttpRequestOptions } options - Optional parameters {@link HttpRequestOptions}.
574     * @returns { Promise<number> } the promise returned by the function.
575     * @throws { BusinessError } 401 - Parameter error.
576     * @throws { BusinessError } 201 - Permission denied.
577     * @throws { BusinessError } 2300001 - Unsupported protocol.
578     * @throws { BusinessError } 2300003 - URL using bad/illegal format or missing URL.
579     * @throws { BusinessError } 2300005 - Couldn't resolve proxy name.
580     * @throws { BusinessError } 2300006 - Couldn't resolve host name.
581     * @throws { BusinessError } 2300007 - Couldn't connect to server.
582     * @throws { BusinessError } 2300008 - Weird server reply.
583     * @throws { BusinessError } 2300009 - Access denied to remote resource.
584     * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer.
585     * @throws { BusinessError } 2300018 - Transferred a partial file.
586     * @throws { BusinessError } 2300023 - Failed writing received data to disk/application.
587     * @throws { BusinessError } 2300025 - Upload failed.
588     * @throws { BusinessError } 2300026 - Failed to open/read local data from file/application.
589     * @throws { BusinessError } 2300027 - Out of memory.
590     * @throws { BusinessError } 2300028 - Timeout was reached.
591     * @throws { BusinessError } 2300047 - Number of redirects hit maximum amount.
592     * @throws { BusinessError } 2300052 - Server returned nothing (no headers, no data).
593     * @throws { BusinessError } 2300055 - Failed sending data to the peer.
594     * @throws { BusinessError } 2300056 - Failure when receiving data from the peer.
595     * @throws { BusinessError } 2300058 - Problem with the local SSL certificate.
596     * @throws { BusinessError } 2300059 - Couldn't use specified SSL cipher.
597     * @throws { BusinessError } 2300060 - SSL peer certificate or SSH remote key was not OK.
598     * @throws { BusinessError } 2300061 - Unrecognized or bad HTTP Content or Transfer-Encoding.
599     * @throws { BusinessError } 2300063 - Maximum file size exceeded.
600     * @throws { BusinessError } 2300070 - Disk full or allocation exceeded.
601     * @throws { BusinessError } 2300073 - Remote file already exists.
602     * @throws { BusinessError } 2300077 - Problem with the SSL CA cert (path? access rights?).
603     * @throws { BusinessError } 2300078 - Remote file not found.
604     * @throws { BusinessError } 2300094 - An authentication function returned an error.
605     * @throws { BusinessError } 2300999 - Unknown Other Error.
606     * @syscap SystemCapability.Communication.NetStack
607     * @since 10
608     */
609    requestInStream(url: string, options?: HttpRequestOptions): Promise<number>;
610
611    /**
612     * Destroys an HTTP request.
613     * @syscap SystemCapability.Communication.NetStack
614     * @since 6
615     */
616    /**
617     * Destroys an HTTP request.
618     * @syscap SystemCapability.Communication.NetStack
619     * @crossplatform
620     * @since 10
621     */
622    destroy(): void;
623
624    /**
625     * Registers an observer for HTTP Response Header events.
626     * @param { "headerReceive" } type - Indicates Event name.
627     * @param { AsyncCallback<Object> } callback - the callback used to return the result.
628     * @syscap SystemCapability.Communication.NetStack
629     * @since 6
630     * @deprecated since 8
631     * @useinstead on_headersReceive
632     */
633    on(type: "headerReceive", callback: AsyncCallback<Object>): void;
634
635    /**
636     * Unregisters the observer for HTTP Response Header events.
637     * @param { "headerReceive" } type - Indicates Event name.
638     * @param { AsyncCallback<Object> } callback - the callback used to return the result.
639     * @syscap SystemCapability.Communication.NetStack
640     * @since 6
641     * @deprecated since 8
642     * @useinstead off_headersReceive
643     */
644    off(type: "headerReceive", callback?: AsyncCallback<Object>): void;
645
646    /**
647     * Registers an observer for HTTP Response Header events.
648     * @param { "headersReceive" } type - Indicates Event name.
649     * @param { Callback<Object> } callback - the callback used to return the result.
650     * @syscap SystemCapability.Communication.NetStack
651     * @since 8
652     */
653    /**
654     * Registers an observer for HTTP Response Header events.
655     * @param { "headersReceive" } type - Indicates Event name.
656     * @param { Callback<Object> } callback - the callback used to return the result.
657     * @syscap SystemCapability.Communication.NetStack
658     * @crossplatform
659     * @since 10
660     */
661    on(type: "headersReceive", callback: Callback<Object>): void;
662
663    /**
664     * Unregisters the observer for HTTP Response Header events.
665     * @param { "headersReceive" } type - Indicates Event name.
666     * @param { Callback<Object> } callback - the callback used to return the result.
667     * @syscap SystemCapability.Communication.NetStack
668     * @since 8
669     */
670    /**
671     * Unregisters the observer for HTTP Response Header events.
672     * @param { "headersReceive" } type - Indicates Event name.
673     * @param { Callback<Object> } callback - the callback used to return the result.
674     * @syscap SystemCapability.Communication.NetStack
675     * @crossplatform
676     * @since 10
677     */
678    off(type: "headersReceive", callback?: Callback<Object>): void;
679
680    /**
681     * Registers a one-time observer for HTTP Response Header events.
682     * @param { "headersReceive" } type - Indicates Event name.
683     * @param { Callback<Object> } callback - the callback used to return the result.
684     * @syscap SystemCapability.Communication.NetStack
685     * @since 8
686     */
687    /**
688     * Registers a one-time observer for HTTP Response Header events.
689     * @param { "headersReceive" } type - Indicates Event name.
690     * @param { Callback<Object> } callback - the callback used to return the result.
691     * @syscap SystemCapability.Communication.NetStack
692     * @crossplatform
693     * @since 10
694     */
695    once(type: "headersReceive", callback: Callback<Object>): void;
696
697    /**
698     * Registers an observer for receiving HTTP Response data events continuously.
699     * @param { "dataReceive" } type - Indicates Event name.
700     * @param { Callback<ArrayBuffer> } callback - the callback used to return the result.
701     * @syscap SystemCapability.Communication.NetStack
702     * @since 10
703     */
704    on(type: "dataReceive", callback: Callback<ArrayBuffer>): void;
705
706    /**
707     * Unregisters an observer for receiving HTTP Response data events continuously.
708     * @param { "dataReceive" } type - Indicates Event name.
709     * @param { Callback<ArrayBuffer> } callback - the callback used to return the result.
710     * @syscap SystemCapability.Communication.NetStack
711     * @since 10
712     */
713    off(type: "dataReceive", callback?: Callback<ArrayBuffer>): void;
714
715    /**
716     * Registers an observer for receiving HTTP Response data ends events.
717     * @param { "dataEnd" } type - Indicates Event name.
718     * @param { Callback<void> } callback - the callback used to return the result.
719     * @syscap SystemCapability.Communication.NetStack
720     * @since 10
721     */
722    on(type: "dataEnd", callback: Callback<void>): void;
723
724    /**
725     * Unregisters an observer for receiving HTTP Response data ends events.
726     * @param { "dataEnd" } type - Indicates Event name.
727     * @param { Callback<void> } callback - the callback used to return the result.
728     * @syscap SystemCapability.Communication.NetStack
729     * @since 10
730     */
731    off(type: "dataEnd", callback?: Callback<void>): void;
732
733    /**
734     * Registers an observer for progress of receiving HTTP Response data events.
735     * @param { 'dataReceiveProgress' } type - Indicates Event name.
736     * @param { Callback<{ receiveSize: number, totalSize: number }> } callback - the callback used to return the result.
737     * @syscap SystemCapability.Communication.NetStack
738     * @since 10
739     */
740    on(type: 'dataReceiveProgress', callback: Callback<{ receiveSize: number, totalSize: number }>): void;
741
742    /**
743     * Unregisters an observer for progress of receiving HTTP Response data events.
744     * @param { 'dataReceiveProgress' } type - Indicates Event name.
745     * @param { Callback<{ receiveSize: number, totalSize: number }> } callback - the callback used to return the result.
746     * @syscap SystemCapability.Communication.NetStack
747     * @since 10
748     */
749    off(type: 'dataReceiveProgress', callback?: Callback<{ receiveSize: number, totalSize: number }>): void;
750  }
751
752  /**
753   * Defines an HTTP request method.
754   * @enum {string}
755   * @syscap SystemCapability.Communication.NetStack
756   * @since 6
757   */
758  /**
759   * Defines an HTTP request method.
760   * @enum {string}
761   * @syscap SystemCapability.Communication.NetStack
762   * @crossplatform
763   * @since 10
764   */
765  export enum RequestMethod {
766    /**
767     * OPTIONS method.
768     * @syscap SystemCapability.Communication.NetStack
769     * @since 6
770     */
771    /**
772     * OPTIONS method.
773     * @syscap SystemCapability.Communication.NetStack
774     * @crossplatform
775     * @since 10
776     */
777    OPTIONS = "OPTIONS",
778
779    /**
780     * GET method.
781     * @syscap SystemCapability.Communication.NetStack
782     * @since 6
783     */
784    /**
785     * GET method.
786     * @syscap SystemCapability.Communication.NetStack
787     * @crossplatform
788     * @since 10
789     */
790    GET = "GET",
791
792    /**
793     * HEAD method.
794     * @syscap SystemCapability.Communication.NetStack
795     * @since 6
796     */
797    /**
798     * HEAD method.
799     * @syscap SystemCapability.Communication.NetStack
800     * @crossplatform
801     * @since 10
802     */
803    HEAD = "HEAD",
804
805    /**
806     * POST method.
807     * @syscap SystemCapability.Communication.NetStack
808     * @since 6
809     */
810    /**
811     * POST method.
812     * @syscap SystemCapability.Communication.NetStack
813     * @crossplatform
814     * @since 10
815     */
816    POST = "POST",
817
818    /**
819     * PUT method.
820     * @syscap SystemCapability.Communication.NetStack
821     * @since 6
822     */
823    /**
824     * PUT method.
825     * @syscap SystemCapability.Communication.NetStack
826     * @crossplatform
827     * @since 10
828     */
829    PUT = "PUT",
830
831    /**
832     * DELETE method.
833     * @syscap SystemCapability.Communication.NetStack
834     * @since 6
835     */
836    /**
837     * DELETE method.
838     * @syscap SystemCapability.Communication.NetStack
839     * @crossplatform
840     * @since 10
841     */
842    DELETE = "DELETE",
843
844    /**
845     * TRACE method.
846     * @syscap SystemCapability.Communication.NetStack
847     * @since 6
848     */
849    /**
850     * TRACE method.
851     * @syscap SystemCapability.Communication.NetStack
852     * @crossplatform
853     * @since 10
854     */
855    TRACE = "TRACE",
856
857    /**
858     * CONNECT method.
859     * @syscap SystemCapability.Communication.NetStack
860     * @since 6
861     */
862    /**
863     * CONNECT method.
864     * @syscap SystemCapability.Communication.NetStack
865     * @crossplatform
866     * @since 10
867     */
868    CONNECT = "CONNECT"
869  }
870
871  /**
872   * Enumerates the response codes for an HTTP request.
873   * @enum {number}
874   * @syscap SystemCapability.Communication.NetStack
875   * @since 6
876   */
877  /**
878   * Enumerates the response codes for an HTTP request.
879   * @enum {number}
880   * @syscap SystemCapability.Communication.NetStack
881   * @crossplatform
882   * @since 10
883   */
884  export enum ResponseCode {
885    /**
886     * The request was successful. Typically used for GET and POST requests.
887     * @syscap SystemCapability.Communication.NetStack
888     * @since 6
889     */
890    /**
891     * The request was successful. Typically used for GET and POST requests.
892     * @syscap SystemCapability.Communication.NetStack
893     * @crossplatform
894     * @since 10
895     */
896    OK = 200,
897
898    /**
899     * Successfully requested and created a new resource.
900     * @syscap SystemCapability.Communication.NetStack
901     * @since 6
902     */
903    /**
904     * Successfully requested and created a new resource.
905     * @syscap SystemCapability.Communication.NetStack
906     * @crossplatform
907     * @since 10
908     */
909    CREATED,
910
911    /**
912     * The request has been accepted but has not been processed completely.
913     * @syscap SystemCapability.Communication.NetStack
914     * @since 6
915     */
916    /**
917     * The request has been accepted but has not been processed completely.
918     * @syscap SystemCapability.Communication.NetStack
919     * @crossplatform
920     * @since 10
921     */
922    ACCEPTED,
923
924    /**
925     * Unauthorized information. The request was successful.
926     * @syscap SystemCapability.Communication.NetStack
927     * @since 6
928     */
929    /**
930     * Unauthorized information. The request was successful.
931     * @syscap SystemCapability.Communication.NetStack
932     * @crossplatform
933     * @since 10
934     */
935    NOT_AUTHORITATIVE,
936
937    /**
938     * No content. The server successfully processed, but did not return content.
939     * @syscap SystemCapability.Communication.NetStack
940     * @since 6
941     */
942    /**
943     * No content. The server successfully processed, but did not return content.
944     * @syscap SystemCapability.Communication.NetStack
945     * @crossplatform
946     * @since 10
947     */
948    NO_CONTENT,
949
950    /**
951     * Reset the content.
952     * @syscap SystemCapability.Communication.NetStack
953     * @since 6
954     */
955    /**
956     * Reset the content.
957     * @syscap SystemCapability.Communication.NetStack
958     * @crossplatform
959     * @since 10
960     */
961    RESET,
962
963    /**
964     * Partial content. The server successfully processed some GET requests.
965     * @syscap SystemCapability.Communication.NetStack
966     * @since 6
967     */
968    /**
969     * Partial content. The server successfully processed some GET requests.
970     * @syscap SystemCapability.Communication.NetStack
971     * @crossplatform
972     * @since 10
973     */
974    PARTIAL,
975
976    /**
977     * Multiple options.
978     * @syscap SystemCapability.Communication.NetStack
979     * @since 6
980     */
981    /**
982     * Multiple options.
983     * @syscap SystemCapability.Communication.NetStack
984     * @crossplatform
985     * @since 10
986     */
987    MULT_CHOICE = 300,
988
989    /**
990     * <p>Permanently move. The requested resource has been permanently moved to a new URI,
991     * and the returned information will include the new URI. The browser will automatically redirect to the new URI.</p>
992     * @syscap SystemCapability.Communication.NetStack
993     * @since 6
994     */
995    /**
996     * <p>Permanently move. The requested resource has been permanently moved to a new URI,
997     * and the returned information will include the new URI. The browser will automatically redirect to the new URI.</p>
998     * @syscap SystemCapability.Communication.NetStack
999     * @crossplatform
1000     * @since 10
1001     */
1002    MOVED_PERM,
1003
1004    /**
1005     * Temporary movement.
1006     * @syscap SystemCapability.Communication.NetStack
1007     * @since 6
1008     */
1009    /**
1010     * Temporary movement.
1011     * @syscap SystemCapability.Communication.NetStack
1012     * @crossplatform
1013     * @since 10
1014     */
1015    MOVED_TEMP,
1016
1017    /**
1018     * View other addresses.
1019     * @syscap SystemCapability.Communication.NetStack
1020     * @since 6
1021     */
1022    /**
1023     * View other addresses.
1024     * @syscap SystemCapability.Communication.NetStack
1025     * @crossplatform
1026     * @since 10
1027     */
1028    SEE_OTHER,
1029
1030    /**
1031     * Not modified.
1032     * @syscap SystemCapability.Communication.NetStack
1033     * @since 6
1034     */
1035    /**
1036     * Not modified.
1037     * @syscap SystemCapability.Communication.NetStack
1038     * @crossplatform
1039     * @since 10
1040     */
1041    NOT_MODIFIED,
1042
1043    /**
1044     * Using proxies.
1045     * @syscap SystemCapability.Communication.NetStack
1046     * @since 6
1047     */
1048    /**
1049     * Using proxies.
1050     * @syscap SystemCapability.Communication.NetStack
1051     * @crossplatform
1052     * @since 10
1053     */
1054    USE_PROXY,
1055
1056    /**
1057     * The server cannot understand the syntax error error requested by the client.
1058     * @syscap SystemCapability.Communication.NetStack
1059     * @since 6
1060     */
1061    /**
1062     * The server cannot understand the syntax error error requested by the client.
1063     * @syscap SystemCapability.Communication.NetStack
1064     * @crossplatform
1065     * @since 10
1066     */
1067    BAD_REQUEST = 400,
1068
1069    /**
1070     * Request for user authentication.
1071     * @syscap SystemCapability.Communication.NetStack
1072     * @since 6
1073     */
1074    /**
1075     * Request for user authentication.
1076     * @syscap SystemCapability.Communication.NetStack
1077     * @crossplatform
1078     * @since 10
1079     */
1080    UNAUTHORIZED,
1081
1082    /**
1083     * Reserved for future use.
1084     * @syscap SystemCapability.Communication.NetStack
1085     * @since 6
1086     */
1087    /**
1088     * Reserved for future use.
1089     * @syscap SystemCapability.Communication.NetStack
1090     * @crossplatform
1091     * @since 10
1092     */
1093    PAYMENT_REQUIRED,
1094
1095    /**
1096     * The server understands the request from the requesting client, but refuses to execute it.
1097     * @syscap SystemCapability.Communication.NetStack
1098     * @since 6
1099     */
1100    /**
1101     * The server understands the request from the requesting client, but refuses to execute it.
1102     * @syscap SystemCapability.Communication.NetStack
1103     * @crossplatform
1104     * @since 10
1105     */
1106    FORBIDDEN,
1107
1108    /**
1109     * The server was unable to find resources (web pages) based on the client's request.
1110     * @syscap SystemCapability.Communication.NetStack
1111     * @since 6
1112     */
1113    /**
1114     * The server was unable to find resources (web pages) based on the client's request.
1115     * @syscap SystemCapability.Communication.NetStack
1116     * @crossplatform
1117     * @since 10
1118     */
1119    NOT_FOUND,
1120
1121    /**
1122     * The method in the client request is prohibited.
1123     * @syscap SystemCapability.Communication.NetStack
1124     * @since 6
1125     */
1126    /**
1127     * The method in the client request is prohibited.
1128     * @syscap SystemCapability.Communication.NetStack
1129     * @crossplatform
1130     * @since 10
1131     */
1132    BAD_METHOD,
1133
1134    /**
1135     * The server is unable to complete the request based on the content characteristics requested by the client.
1136     * @syscap SystemCapability.Communication.NetStack
1137     * @since 6
1138     */
1139    /**
1140     * The server is unable to complete the request based on the content characteristics requested by the client.
1141     * @syscap SystemCapability.Communication.NetStack
1142     * @crossplatform
1143     * @since 10
1144     */
1145    NOT_ACCEPTABLE,
1146
1147    /**
1148     * Request authentication of the proxy's identity.
1149     * @syscap SystemCapability.Communication.NetStack
1150     * @since 6
1151     */
1152    /**
1153     * Request authentication of the proxy's identity.
1154     * @syscap SystemCapability.Communication.NetStack
1155     * @crossplatform
1156     * @since 10
1157     */
1158    PROXY_AUTH,
1159
1160    /**
1161     * The request took too long and timed out.
1162     * @syscap SystemCapability.Communication.NetStack
1163     * @since 6
1164     */
1165    /**
1166     * The request took too long and timed out.
1167     * @syscap SystemCapability.Communication.NetStack
1168     * @crossplatform
1169     * @since 10
1170     */
1171    CLIENT_TIMEOUT,
1172
1173    /**
1174     * <p>The server may have returned this code when completing the client's PUT request,
1175     * as there was a conflict when the server was processing the request.</p>
1176     * @syscap SystemCapability.Communication.NetStack
1177     * @since 6
1178     */
1179    /**
1180     * <p>The server may have returned this code when completing the client's PUT request,
1181     * as there was a conflict when the server was processing the request.</p>
1182     * @syscap SystemCapability.Communication.NetStack
1183     * @crossplatform
1184     * @since 10
1185     */
1186    CONFLICT,
1187
1188    /**
1189     * The resource requested by the client no longer exists.
1190     * @syscap SystemCapability.Communication.NetStack
1191     * @since 6
1192     */
1193    /**
1194     * The resource requested by the client no longer exists.
1195     * @syscap SystemCapability.Communication.NetStack
1196     * @crossplatform
1197     * @since 10
1198     */
1199    GONE,
1200
1201    /**
1202     * The server is unable to process request information sent by the client without Content Length.
1203     * @syscap SystemCapability.Communication.NetStack
1204     * @since 6
1205     */
1206    /**
1207     * The server is unable to process request information sent by the client without Content Length.
1208     * @syscap SystemCapability.Communication.NetStack
1209     * @crossplatform
1210     * @since 10
1211     */
1212    LENGTH_REQUIRED,
1213
1214    /**
1215     * The prerequisite for requesting information from the client is incorrect.
1216     * @syscap SystemCapability.Communication.NetStack
1217     * @since 6
1218     */
1219    /**
1220     * The prerequisite for requesting information from the client is incorrect.
1221     * @syscap SystemCapability.Communication.NetStack
1222     * @crossplatform
1223     * @since 10
1224     */
1225    PRECON_FAILED,
1226
1227    /**
1228     * The request was rejected because the requested entity was too large for the server to process.
1229     * @syscap SystemCapability.Communication.NetStack
1230     * @since 6
1231     */
1232    /**
1233     * The request was rejected because the requested entity was too large for the server to process.
1234     * @syscap SystemCapability.Communication.NetStack
1235     * @crossplatform
1236     * @since 10
1237     */
1238    ENTITY_TOO_LARGE,
1239
1240    /**
1241     * The requested URI is too long (usually a URL) and the server cannot process it.
1242     * @syscap SystemCapability.Communication.NetStack
1243     * @since 6
1244     */
1245    /**
1246     * The requested URI is too long (usually a URL) and the server cannot process it.
1247     * @syscap SystemCapability.Communication.NetStack
1248     * @crossplatform
1249     * @since 10
1250     */
1251    REQ_TOO_LONG,
1252
1253    /**
1254     * The server is unable to process the requested format.
1255     * @syscap SystemCapability.Communication.NetStack
1256     * @since 6
1257     */
1258    /**
1259     * The server is unable to process the requested format.
1260     * @syscap SystemCapability.Communication.NetStack
1261     * @crossplatform
1262     * @since 10
1263     */
1264    UNSUPPORTED_TYPE,
1265
1266    /**
1267     * Internal server error, unable to complete the request.
1268     * @syscap SystemCapability.Communication.NetStack
1269     * @since 6
1270     */
1271    /**
1272     * Internal server error, unable to complete the request.
1273     * @syscap SystemCapability.Communication.NetStack
1274     * @crossplatform
1275     * @since 10
1276     */
1277    INTERNAL_ERROR = 500,
1278
1279    /**
1280     * The server does not support the requested functionality and cannot complete the request.
1281     * @syscap SystemCapability.Communication.NetStack
1282     * @since 6
1283     */
1284    /**
1285     * The server does not support the requested functionality and cannot complete the request.
1286     * @syscap SystemCapability.Communication.NetStack
1287     * @crossplatform
1288     * @since 10
1289     */
1290    NOT_IMPLEMENTED,
1291
1292    /**
1293     * The server acting as a gateway or proxy received an invalid request from the remote server.
1294     * @syscap SystemCapability.Communication.NetStack
1295     * @since 6
1296     */
1297    /**
1298     * The server acting as a gateway or proxy received an invalid request from the remote server.
1299     * @syscap SystemCapability.Communication.NetStack
1300     * @crossplatform
1301     * @since 10
1302     */
1303    BAD_GATEWAY,
1304
1305    /**
1306     * Due to overload or system maintenance, the server is temporarily unable to process client requests.
1307     * @syscap SystemCapability.Communication.NetStack
1308     * @since 6
1309     */
1310    /**
1311     * Due to overload or system maintenance, the server is temporarily unable to process client requests.
1312     * @syscap SystemCapability.Communication.NetStack
1313     * @crossplatform
1314     * @since 10
1315     */
1316    UNAVAILABLE,
1317
1318    /**
1319     * The server acting as a gateway or proxy did not obtain requests from the remote server in a timely manner.
1320     * @syscap SystemCapability.Communication.NetStack
1321     * @since 6
1322     */
1323    /**
1324     * The server acting as a gateway or proxy did not obtain requests from the remote server in a timely manner.
1325     * @syscap SystemCapability.Communication.NetStack
1326     * @crossplatform
1327     * @since 10
1328     */
1329    GATEWAY_TIMEOUT,
1330
1331    /**
1332     * The version of the HTTP protocol requested by the server.
1333     * @syscap SystemCapability.Communication.NetStack
1334     * @since 6
1335     */
1336    /**
1337     * The version of the HTTP protocol requested by the server.
1338     * @syscap SystemCapability.Communication.NetStack
1339     * @crossplatform
1340     * @since 10
1341     */
1342    VERSION
1343  }
1344
1345  /**
1346   * Supported protocols.
1347   * @enum {string}
1348   * @syscap SystemCapability.Communication.NetStack
1349   * @since 9
1350   */
1351  /**
1352   * Supported protocols.
1353   * @enum {string}
1354   * @syscap SystemCapability.Communication.NetStack
1355   * @crossplatform
1356   * @since 10
1357   */
1358  export enum HttpProtocol {
1359    /**
1360     * Protocol http1.1
1361     * @syscap SystemCapability.Communication.NetStack
1362     * @since 9
1363     */
1364    /**
1365     * Protocol http1.1
1366     * @syscap SystemCapability.Communication.NetStack
1367     * @crossplatform
1368     * @since 10
1369     */
1370    HTTP1_1,
1371
1372    /**
1373     * Protocol http2
1374     * @syscap SystemCapability.Communication.NetStack
1375     * @since 9
1376     */
1377    /**
1378     * Protocol http2
1379     * @syscap SystemCapability.Communication.NetStack
1380     * @crossplatform
1381     * @since 10
1382     */
1383    HTTP2
1384  }
1385
1386  /**
1387   * Indicates the type of the returned data.
1388   * @enum {number}
1389   * @syscap SystemCapability.Communication.NetStack
1390   * @since 9
1391   */
1392  /**
1393   * Indicates the type of the returned data.
1394   * @enum {number}
1395   * @syscap SystemCapability.Communication.NetStack
1396   * @crossplatform
1397   * @since 10
1398   */
1399  export enum HttpDataType {
1400    /**
1401     * The returned type is string.
1402     * @syscap SystemCapability.Communication.NetStack
1403     * @since 9
1404     */
1405    /**
1406     * The returned type is string.
1407     * @syscap SystemCapability.Communication.NetStack
1408     * @crossplatform
1409     * @since 10
1410     */
1411    STRING,
1412
1413    /**
1414     * The returned type is Object.
1415     * @syscap SystemCapability.Communication.NetStack
1416     * @since 9
1417     */
1418    /**
1419     * The returned type is Object.
1420     * @syscap SystemCapability.Communication.NetStack
1421     * @crossplatform
1422     * @since 10
1423     */
1424    OBJECT = 1,
1425
1426    /**
1427     * The returned type is ArrayBuffer.
1428     * @syscap SystemCapability.Communication.NetStack
1429     * @since 9
1430     */
1431    /**
1432     * The returned type is ArrayBuffer.
1433     * @syscap SystemCapability.Communication.NetStack
1434     * @crossplatform
1435     * @since 10
1436     */
1437    ARRAY_BUFFER = 2
1438  }
1439
1440  /**
1441   * Defines the response to an HTTP request.
1442   * @interface HttpResponse
1443   * @syscap SystemCapability.Communication.NetStack
1444   * @since 6
1445   */
1446  /**
1447   * Defines the response to an HTTP request.
1448   * @interface HttpResponse
1449   * @syscap SystemCapability.Communication.NetStack
1450   * @crossplatform
1451   * @since 10
1452   */
1453  export interface HttpResponse {
1454    /**
1455     * result can be a string (API 6) or an ArrayBuffer(API 8). Object is deprecated from API 8.
1456     * If {@link HttpRequestOptions#expectDataType} is set, the system preferentially returns this parameter.
1457     * @type {string | Object | ArrayBuffer}
1458     * @syscap SystemCapability.Communication.NetStack
1459     * @since 6
1460     */
1461    /**
1462     * result can be a string (API 6) or an ArrayBuffer(API 8). Object is deprecated from API 8.
1463     * If {@link HttpRequestOptions#expectDataType} is set, the system preferentially returns this parameter.
1464     * @type {string | Object | ArrayBuffer}
1465     * @syscap SystemCapability.Communication.NetStack
1466     * @crossplatform
1467     * @since 10
1468     */
1469    result: string | Object | ArrayBuffer;
1470
1471    /**
1472     * If the resultType is string, you can get result directly.
1473     * If the resultType is Object, you can get result such as this: result['key'].
1474     * If the resultType is ArrayBuffer, you can use ArrayBuffer to create the binary objects.
1475     * @type {HttpDataType}
1476     * @syscap SystemCapability.Communication.NetStack
1477     * @since 9
1478     */
1479    /**
1480     * If the resultType is string, you can get result directly.
1481     * If the resultType is Object, you can get result such as this: result['key'].
1482     * If the resultType is ArrayBuffer, you can use ArrayBuffer to create the binary objects.
1483     * @type {HttpDataType}
1484     * @syscap SystemCapability.Communication.NetStack
1485     * @crossplatform
1486     * @since 10
1487     */
1488    resultType: HttpDataType;
1489
1490    /**
1491     * Server status code.
1492     * @type {ResponseCode | number}
1493     * @syscap SystemCapability.Communication.NetStack
1494     * @since 6
1495     */
1496    /**
1497     * Server status code.
1498     * @type {ResponseCode | number}
1499     * @syscap SystemCapability.Communication.NetStack
1500     * @crossplatform
1501     * @since 10
1502     */
1503    responseCode: ResponseCode | number;
1504
1505    /**
1506     * All headers in the response from the server.
1507     * @type {Object}
1508     * @syscap SystemCapability.Communication.NetStack
1509     * @since 6
1510     */
1511    /**
1512     * All headers in the response from the server.
1513     * @type {Object}
1514     * @syscap SystemCapability.Communication.NetStack
1515     * @crossplatform
1516     * @since 10
1517     */
1518    header: Object;
1519
1520    /**
1521     * Cookies returned by the server.
1522     * @type {string}
1523     * @syscap SystemCapability.Communication.NetStack
1524     * @since 8
1525     */
1526    /**
1527     * Cookies returned by the server.
1528     * @type {string}
1529     * @syscap SystemCapability.Communication.NetStack
1530     * @crossplatform
1531     * @since 10
1532     */
1533    cookies: string;
1534  }
1535
1536  /**
1537   * Creates a default {@code HttpResponseCache} object to store the responses of HTTP access requests.
1538   * @param { number } cacheSize - the size of cache(max value is 10MB), default is 10*1024*1024(10MB).
1539   * @returns { HttpResponseCache } the HttpResponseCache of the createHttpResponseCache.
1540   * @syscap SystemCapability.Communication.NetStack
1541   * @since 9
1542   */
1543  /**
1544   * Creates a default {@code HttpResponseCache} object to store the responses of HTTP access requests.
1545   * @param { number } cacheSize - the size of cache(max value is 10MB), default is 10*1024*1024(10MB).
1546   * @returns { HttpResponseCache } the HttpResponseCache of the createHttpResponseCache.
1547   * @syscap SystemCapability.Communication.NetStack
1548   * @crossplatform
1549   * @since 10
1550   */
1551  function createHttpResponseCache(cacheSize?: number): HttpResponseCache;
1552
1553  /**
1554   * Defines an object that stores the response to an HTTP request.
1555   * @interface HttpResponseCache
1556   * @syscap SystemCapability.Communication.NetStack
1557   * @since 9
1558   */
1559  /**
1560   * Defines an object that stores the response to an HTTP request.
1561   * @interface HttpResponseCache
1562   * @syscap SystemCapability.Communication.NetStack
1563   * @crossplatform
1564   * @since 10
1565   */
1566  export interface HttpResponseCache {
1567    /**
1568     * Writes data in the cache to the file system so that all the cached data can be accessed in the next HTTP request.
1569     * @param { AsyncCallback<void> } callback - the callback of flush.
1570     * @syscap SystemCapability.Communication.NetStack
1571     * @since 9
1572     */
1573    /**
1574     * Writes data in the cache to the file system so that all the cached data can be accessed in the next HTTP request.
1575     * @param { AsyncCallback<void> } callback - the callback of flush.
1576     * @syscap SystemCapability.Communication.NetStack
1577     * @crossplatform
1578     * @since 10
1579     */
1580    flush(callback: AsyncCallback<void>): void;
1581
1582    /**
1583     * Writes data in the cache to the file system so that all the cached data can be accessed in the next HTTP request.
1584     * @returns { Promise<void> } The promise returned by the flush.
1585     * @syscap SystemCapability.Communication.NetStack
1586     * @since 9
1587     */
1588    /**
1589     * Writes data in the cache to the file system so that all the cached data can be accessed in the next HTTP request.
1590     * @returns { Promise<void> } The promise returned by the flush.
1591     * @syscap SystemCapability.Communication.NetStack
1592     * @crossplatform
1593     * @since 10
1594     */
1595    flush(): Promise<void>;
1596
1597    /**
1598     * Disables a cache and deletes the data in it.
1599     * @param { AsyncCallback<void> } callback - the callback of delete.
1600     * @syscap SystemCapability.Communication.NetStack
1601     * @since 9
1602     */
1603    /**
1604     * Disables a cache and deletes the data in it.
1605     * @param { AsyncCallback<void> } callback - the callback of delete.
1606     * @syscap SystemCapability.Communication.NetStack
1607     * @crossplatform
1608     * @since 10
1609     */
1610    delete(callback: AsyncCallback<void>): void;
1611
1612    /**
1613     * Disables a cache and deletes the data in it.
1614     * @returns { Promise<void> } The promise returned by the delete.
1615     * @syscap SystemCapability.Communication.NetStack
1616     * @since 9
1617     */
1618    /**
1619     * Disables a cache and deletes the data in it.
1620     * @returns { Promise<void> } The promise returned by the delete.
1621     * @syscap SystemCapability.Communication.NetStack
1622     * @crossplatform
1623     * @since 10
1624     */
1625    delete(): Promise<void>;
1626  }
1627}
1628
1629export default http;
1630