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 16/** 17 * @file 18 * @kit NetworkKit 19 */ 20 21import type { AsyncCallback, Callback } from './@ohos.base'; 22import type connection from './@ohos.net.connection'; 23 24/** 25 * Provides http related APIs. 26 * @namespace http 27 * @syscap SystemCapability.Communication.NetStack 28 * @since 6 29 */ 30/** 31 * Provides http related APIs. 32 * @namespace http 33 * @syscap SystemCapability.Communication.NetStack 34 * @crossplatform 35 * @since 10 36 */ 37/** 38 * Provides http related APIs. 39 * @namespace http 40 * @syscap SystemCapability.Communication.NetStack 41 * @crossplatform 42 * @atomicservice 43 * @since 11 44 */ 45declare namespace http { 46 /** 47 * @syscap SystemCapability.Communication.NetStack 48 * @since 10 49 */ 50 /** 51 * @syscap SystemCapability.Communication.NetStack 52 * @atomicservice 53 * @since 11 54 */ 55 /** 56 * @typedef { connection.HttpProxy } 57 * @syscap SystemCapability.Communication.NetStack 58 * @crossplatform 59 * @atomicservice 60 * @since 12 61 */ 62 type HttpProxy = connection.HttpProxy; 63 64 /** 65 * Creates an HTTP request task. 66 * @returns { HttpRequest } the HttpRequest of the createHttp. 67 * @syscap SystemCapability.Communication.NetStack 68 * @since 6 69 */ 70 /** 71 * Creates an HTTP request task. 72 * @returns { HttpRequest } the HttpRequest of the createHttp. 73 * @syscap SystemCapability.Communication.NetStack 74 * @crossplatform 75 * @since 10 76 */ 77 /** 78 * Creates an HTTP request task. 79 * @returns { HttpRequest } the HttpRequest of the createHttp. 80 * @syscap SystemCapability.Communication.NetStack 81 * @crossplatform 82 * @atomicservice 83 * @since 11 84 */ 85 function createHttp(): HttpRequest; 86 87 /** 88 * Enum for Address Family 89 * @enum {string} 90 * @syscap SystemCapability.Communication.NetStack 91 * @since 16 92 */ 93 export enum AddressFamily { 94 /** 95 * Default, can use addresses of all IP versions that your system allows. 96 * @syscap SystemCapability.Communication.NetStack 97 * @crossplatform 98 * @since 16 99 */ 100 DEFAULT = 'CURL_IPRESOLVE_WHATEVER', 101 102 /** 103 * ONLYV4 Uses only IPv4 addresses. 104 * @syscap SystemCapability.Communication.NetStack 105 * @crossplatform 106 * @since 16 107 */ 108 ONLY_V4 = 'CURL_IPRESOLVE_V4', 109 110 /** 111 * ONLYV6 Uses only IPv6 addresses. 112 * @syscap SystemCapability.Communication.NetStack 113 * @crossplatform 114 * @since 16 115 */ 116 ONLY_V6 = 'CURL_IPRESOLVE_V6' 117 } 118 119 /** 120 * Specifies the type and value range of the optional parameters in the HTTP request. 121 * @interface HttpRequestOptions 122 * @syscap SystemCapability.Communication.NetStack 123 * @since 6 124 */ 125 /** 126 * Specifies the type and value range of the optional parameters in the HTTP request. 127 * @interface HttpRequestOptions 128 * @syscap SystemCapability.Communication.NetStack 129 * @crossplatform 130 * @since 10 131 */ 132 /** 133 * Specifies the type and value range of the optional parameters in the HTTP request. 134 * @interface HttpRequestOptions 135 * @syscap SystemCapability.Communication.NetStack 136 * @crossplatform 137 * @atomicservice 138 * @since 11 139 */ 140 export interface HttpRequestOptions { 141 /** 142 * Request method,default is GET. 143 * @type {?RequestMethod} 144 * @syscap SystemCapability.Communication.NetStack 145 * @since 6 146 */ 147 /** 148 * Request method,default is GET. 149 * @type {?RequestMethod} 150 * @syscap SystemCapability.Communication.NetStack 151 * @crossplatform 152 * @since 10 153 */ 154 /** 155 * Request method,default is GET. 156 * @type {?RequestMethod} 157 * @syscap SystemCapability.Communication.NetStack 158 * @crossplatform 159 * @atomicservice 160 * @since 11 161 */ 162 method?: RequestMethod; 163 164 /** 165 * Additional data of the request. 166 * extraData can be a string or an Object (API 6) or an ArrayBuffer(API 8). 167 * @type {?string | Object | ArrayBuffer} 168 * @syscap SystemCapability.Communication.NetStack 169 * @since 6 170 */ 171 /** 172 * Additional data of the request. 173 * extraData can be a string or an Object (API 6) or an ArrayBuffer(API 8). 174 * @type {?string | Object | ArrayBuffer} 175 * @syscap SystemCapability.Communication.NetStack 176 * @crossplatform 177 * @since 10 178 */ 179 /** 180 * Additional data of the request. 181 * extraData can be a string or an Object (API 6) or an ArrayBuffer(API 8). 182 * @type { ?(string | Object | ArrayBuffer) } 183 * @syscap SystemCapability.Communication.NetStack 184 * @crossplatform 185 * @atomicservice 186 * @since 11 187 */ 188 extraData?: string | Object | ArrayBuffer; 189 190 /** 191 * Data type to be returned. If this parameter is set, the system preferentially returns the specified type. 192 * @type {?HttpDataType} 193 * @syscap SystemCapability.Communication.NetStack 194 * @since 9 195 */ 196 /** 197 * Data type to be returned. If this parameter is set, the system preferentially returns the specified type. 198 * @type {?HttpDataType} 199 * @syscap SystemCapability.Communication.NetStack 200 * @crossplatform 201 * @since 10 202 */ 203 /** 204 * Data type to be returned. If this parameter is set, the system preferentially returns the specified type. 205 * @type {?HttpDataType} 206 * @syscap SystemCapability.Communication.NetStack 207 * @crossplatform 208 * @atomicservice 209 * @since 11 210 */ 211 expectDataType?: HttpDataType; 212 213 /** 214 * default is true 215 * @type {?boolean} 216 * @syscap SystemCapability.Communication.NetStack 217 * @since 9 218 */ 219 /** 220 * default is true 221 * @type {?boolean} 222 * @syscap SystemCapability.Communication.NetStack 223 * @crossplatform 224 * @since 10 225 */ 226 /** 227 * default is true 228 * @type {?boolean} 229 * @syscap SystemCapability.Communication.NetStack 230 * @crossplatform 231 * @atomicservice 232 * @since 11 233 */ 234 usingCache?: boolean; 235 236 /** 237 * [1, 1000], default is 1. 238 * @type {?number} 239 * @syscap SystemCapability.Communication.NetStack 240 * @since 9 241 */ 242 /** 243 * [1, 1000], default is 1. 244 * @type {?number} 245 * @syscap SystemCapability.Communication.NetStack 246 * @crossplatform 247 * @since 10 248 */ 249 /** 250 * [1, 1000], default is 1. 251 * @type {?number} 252 * @syscap SystemCapability.Communication.NetStack 253 * @crossplatform 254 * @atomicservice 255 * @since 11 256 */ 257 priority?: number; 258 259 /** 260 * HTTP request header. default is 'content-type': 'application/json' 261 * @type {?Object} 262 * @syscap SystemCapability.Communication.NetStack 263 * @since 6 264 */ 265 /** 266 * HTTP request header. default is 'content-type': 'application/json' 267 * @type {?Object} 268 * @syscap SystemCapability.Communication.NetStack 269 * @crossplatform 270 * @since 10 271 */ 272 /** 273 * HTTP request header. default is 'content-type': 'application/json' 274 * @type {?Object} 275 * @syscap SystemCapability.Communication.NetStack 276 * @crossplatform 277 * @atomicservice 278 * @since 11 279 */ 280 header?: Object; 281 282 /** 283 * Read timeout period. The default value is 60,000, in ms. 284 * @type {?number} 285 * @syscap SystemCapability.Communication.NetStack 286 * @since 6 287 */ 288 /** 289 * Read timeout period. The default value is 60,000, in ms. 290 * @type {?number} 291 * @syscap SystemCapability.Communication.NetStack 292 * @crossplatform 293 * @since 10 294 */ 295 /** 296 * Read timeout period. The default value is 60,000, in ms. 297 * @type {?number} 298 * @syscap SystemCapability.Communication.NetStack 299 * @crossplatform 300 * @atomicservice 301 * @since 11 302 */ 303 readTimeout?: number; 304 305 /** 306 * Connection timeout interval. The default value is 60,000, in ms. 307 * @type {?number} 308 * @syscap SystemCapability.Communication.NetStack 309 * @since 6 310 */ 311 /** 312 * Connection timeout interval. The default value is 60,000, in ms. 313 * @type {?number} 314 * @syscap SystemCapability.Communication.NetStack 315 * @crossplatform 316 * @since 10 317 */ 318 /** 319 * Connection timeout interval. The default value is 60,000, in ms. 320 * @type {?number} 321 * @syscap SystemCapability.Communication.NetStack 322 * @crossplatform 323 * @atomicservice 324 * @since 11 325 */ 326 connectTimeout?: number; 327 328 /** 329 * default is automatically specified by the system. 330 * @type {?HttpProtocol} 331 * @syscap SystemCapability.Communication.NetStack 332 * @since 9 333 */ 334 /** 335 * default is automatically specified by the system. 336 * @type {?HttpProtocol} 337 * @syscap SystemCapability.Communication.NetStack 338 * @crossplatform 339 * @since 10 340 */ 341 /** 342 * default is automatically specified by the system. 343 * @type {?HttpProtocol} 344 * @syscap SystemCapability.Communication.NetStack 345 * @crossplatform 346 * @atomicservice 347 * @since 11 348 */ 349 usingProtocol?: HttpProtocol; 350 351 /** 352 * If this parameter is set as type of boolean, the system will use default proxy or not use proxy. 353 * If this parameter is set as type of HttpProxy, the system will use the specified HttpProxy. 354 * @type {?boolean | HttpProxy} 355 * @syscap SystemCapability.Communication.NetStack 356 * @since 10 357 */ 358 /** 359 * If this parameter is set as type of boolean, the system will use default proxy or not use proxy. 360 * If this parameter is set as type of HttpProxy, the system will use the specified HttpProxy. 361 * @type { ?(boolean | HttpProxy) } 362 * @syscap SystemCapability.Communication.NetStack 363 * @atomicservice 364 * @since 11 365 */ 366 /** 367 * If this parameter is set as type of boolean, the system will use default proxy or not use proxy. 368 * If this parameter is set as type of HttpProxy, the system will use the specified HttpProxy. 369 * @type { ?(boolean | HttpProxy) } 370 * @syscap SystemCapability.Communication.NetStack 371 * @crossplatform 372 * @atomicservice 373 * @since 12 374 */ 375 usingProxy?: boolean | HttpProxy; 376 377 /** 378 * If this parameter is set, the system will use ca path specified by user, or else use preset ca by the system. 379 * @type {?string} 380 * @syscap SystemCapability.Communication.NetStack 381 * @since 10 382 */ 383 /** 384 * If this parameter is set, the system will use ca path specified by user, or else use preset ca by the system. 385 * @type {?string} 386 * @syscap SystemCapability.Communication.NetStack 387 * @atomicservice 388 * @since 11 389 */ 390 /** 391 * If this parameter is set, the system will use ca path specified by user, or else use preset ca by the system. 392 * @type {?string} 393 * @syscap SystemCapability.Communication.NetStack 394 * @crossplatform 395 * @atomicservice 396 * @since 12 397 */ 398 caPath?: string; 399 400 /** 401 * Used to set to uploading or downloading the start bytes. The default value is 0. 402 * HTTP standard (RFC 7233 section 3.1) allows servers to ignore range requests. 403 * For HTTP PUT uploads this option should not be used, since it may conflict with other options. 404 * @type {?number} 405 * @syscap SystemCapability.Communication.NetStack 406 * @since 11 407 */ 408 /** 409 * Used to set to uploading or downloading the start bytes. The default value is 0. 410 * HTTP standard (RFC 7233 section 3.1) allows servers to ignore range requests. 411 * For HTTP PUT uploads this option should not be used, since it may conflict with other options. 412 * @type {?number} 413 * @syscap SystemCapability.Communication.NetStack 414 * @crossplatform 415 * @since 12 416 */ 417 resumeFrom?: number; 418 419 /** 420 * Used to set to uploading or downloading the end bytes. Translate to the end if not set. 421 * HTTP standard (RFC 7233 section 3.1) allows servers to ignore range requests. 422 * For HTTP PUT uploads this option should not be used, since it may conflict with other options. 423 * @type {?number} 424 * @syscap SystemCapability.Communication.NetStack 425 * @since 11 426 */ 427 /** 428 * Used to set to uploading or downloading the end bytes. Translate to the end if not set. 429 * HTTP standard (RFC 7233 section 3.1) allows servers to ignore range requests. 430 * For HTTP PUT uploads this option should not be used, since it may conflict with other options. 431 * @type {?number} 432 * @syscap SystemCapability.Communication.NetStack 433 * @crossplatform 434 * @since 12 435 */ 436 resumeTo?: number; 437 438 /** 439 * Support the application to pass in client certificates, allowing the server to verify the client's identity. 440 * @type {?ClientCert} 441 * @syscap SystemCapability.Communication.NetStack 442 * @since 11 443 */ 444 /** 445 * Support the application to pass in client certificates, allowing the server to verify the client's identity. 446 * @type {?ClientCert} 447 * @syscap SystemCapability.Communication.NetStack 448 * @crossplatform 449 * @since 12 450 */ 451 clientCert?: ClientCert; 452 453 /** 454 * If this parameter is set, incoming DNS resolution server URL for the DoH server to use for name resolving. 455 * The parameter must be URL-encoded in the following format: "https://host:port/path". 456 * It MUST specify an HTTPS URL. 457 * @type {?string} 458 * @syscap SystemCapability.Communication.NetStack 459 * @since 11 460 */ 461 /** 462 * If this parameter is set, incoming DNS resolution server URL for the DoH server to use for name resolving. 463 * The parameter must be URL-encoded in the following format: "https://host:port/path". 464 * It MUST specify an HTTPS URL. 465 * @type {?string} 466 * @syscap SystemCapability.Communication.NetStack 467 * @crossplatform 468 * @since 12 469 */ 470 dnsOverHttps?: string; 471 472 /** 473 * If this parameter is set, use the specified DNS server for DNS resolution. 474 * Multiple DNS resolution servers can be set up, with a maximum of 3 servers. 475 * Only take the first three if there are more than three. 476 * @type {?Array<string>} 477 * @syscap SystemCapability.Communication.NetStack 478 * @since 11 479 */ 480 /** 481 * If this parameter is set, use the specified DNS server for DNS resolution. 482 * Multiple DNS resolution servers can be set up, with a maximum of 3 servers. 483 * Only take the first three if there are more than three. 484 * @type {?Array<string>} 485 * @syscap SystemCapability.Communication.NetStack 486 * @crossplatform 487 * @since 12 488 */ 489 dnsServers?: Array<string>; 490 491 /** 492 * The maximum limit of the response body. The default value is 5 * 1024 * 1024, in Byte. 493 * The maximum value is 100 * 1024 *1024, in Byte. 494 * @type {?number} 495 * @syscap SystemCapability.Communication.NetStack 496 * @since 11 497 */ 498 /** 499 * The maximum limit of the response body. The default value is 5 * 1024 * 1024, in Byte. 500 * The maximum value is 100 * 1024 *1024, in Byte. 501 * @type {?number} 502 * @syscap SystemCapability.Communication.NetStack 503 * @crossplatform 504 * @since 12 505 */ 506 maxLimit?: number; 507 508 /** 509 * The data fields which is supported by the HTTP protocol to post 510 * forms and by the SMTP and IMAP protocols to provide 511 * the email data to send/upload. 512 * @type {?Array<MultiFormData>} 513 * @syscap SystemCapability.Communication.NetStack 514 * @since 11 515 */ 516 /** 517 * The data fields which is supported by the HTTP protocol to post 518 * forms and by the SMTP and IMAP protocols to provide 519 * the email data to send/upload. 520 * @type {?Array<MultiFormData>} 521 * @syscap SystemCapability.Communication.NetStack 522 * @crossplatform 523 * @since 12 524 */ 525 multiFormDataList?: Array<MultiFormData>; 526 527 /** 528 * Certificate pinning option. If server certificate's digest does not match 529 * {@link CertificatePinning.publicKeyHash}, request will fail. 530 * @type {?(CertificatePinning | CertificatePinning[])} 531 * @syscap SystemCapability.Communication.NetStack 532 * @since 12 533 */ 534 certificatePinning?: CertificatePinning | CertificatePinning[]; 535 536 /** 537 * Address family option. 538 * @type {AddressFamily} 539 * @syscap SystemCapability.Communication.NetStack 540 * @crossplatform 541 * @since 16 542 */ 543 addressFamily?: AddressFamily; 544 } 545 546 /** 547 * Represents the properties of a form object. 548 * @interface MultiFormData 549 * @syscap SystemCapability.Communication.NetStack 550 * @since 11 551 */ 552 /** 553 * Represents the properties of a form object. 554 * @interface MultiFormData 555 * @syscap SystemCapability.Communication.NetStack 556 * @crossplatform 557 * @since 12 558 */ 559 export interface MultiFormData { 560 /** 561 * MIME name for the data field. 562 * @type {string} 563 * @syscap SystemCapability.Communication.NetStack 564 * @since 11 565 */ 566 /** 567 * MIME name for the data field. 568 * @type {string} 569 * @syscap SystemCapability.Communication.NetStack 570 * @crossplatform 571 * @since 12 572 */ 573 name: string; 574 575 /** 576 * Content type of the data field. 577 * @type {string} 578 * @syscap SystemCapability.Communication.NetStack 579 * @since 11 580 */ 581 /** 582 * Content type of the data field. 583 * @type {string} 584 * @syscap SystemCapability.Communication.NetStack 585 * @crossplatform 586 * @since 12 587 */ 588 contentType: string; 589 590 /** 591 * Remote file name for the data field. 592 * @type {?string} 593 * @syscap SystemCapability.Communication.NetStack 594 * @since 11 595 */ 596 /** 597 * Remote file name for the data field. 598 * @type {?string} 599 * @syscap SystemCapability.Communication.NetStack 600 * @crossplatform 601 * @since 12 602 */ 603 remoteFileName?: string; 604 605 /** 606 * This parameter sets a mime part's body content from memory data. 607 * @type {?(string | Object | ArrayBuffer)} 608 * @syscap SystemCapability.Communication.NetStack 609 * @since 11 610 */ 611 /** 612 * This parameter sets a mime part's body content from memory data. 613 * @type {?(string | Object | ArrayBuffer)} 614 * @syscap SystemCapability.Communication.NetStack 615 * @crossplatform 616 * @since 12 617 */ 618 data?: string | Object | ArrayBuffer; 619 620 /** 621 * This parameter sets a mime part's body content from the file's contents. 622 * This is an alternative to curl_mime_data for setting data to a mime part. 623 * If data is empty, filePath must be set. 624 * If data has a value, filePath does not take effect. 625 * @type {?string} 626 * @syscap SystemCapability.Communication.NetStack 627 * @since 11 628 */ 629 /** 630 * This parameter sets a mime part's body content from the file's contents. 631 * This is an alternative to curl_mime_data for setting data to a mime part. 632 * If data is empty, filePath must be set. 633 * If data has a value, filePath does not take effect. 634 * @type {?string} 635 * @syscap SystemCapability.Communication.NetStack 636 * @crossplatform 637 * @since 12 638 */ 639 filePath?: string; 640 } 641 642 /** 643 * Enum for certificate types 644 * @enum {string} 645 * @syscap SystemCapability.Communication.NetStack 646 * @since 11 647 */ 648 /** 649 * Enum for certificate types 650 * @enum {string} 651 * @syscap SystemCapability.Communication.NetStack 652 * @crossplatform 653 * @since 12 654 */ 655 export enum CertType { 656 /** 657 * PEM format certificate 658 * @syscap SystemCapability.Communication.NetStack 659 * @since 11 660 */ 661 /** 662 * PEM format certificate 663 * @syscap SystemCapability.Communication.NetStack 664 * @crossplatform 665 * @since 12 666 */ 667 PEM = 'PEM', 668 669 /** 670 * DER format certificate 671 * @syscap SystemCapability.Communication.NetStack 672 * @since 11 673 */ 674 /** 675 * DER format certificate 676 * @syscap SystemCapability.Communication.NetStack 677 * @crossplatform 678 * @since 12 679 */ 680 DER = 'DER', 681 682 /** 683 * P12 format certificate 684 * @syscap SystemCapability.Communication.NetStack 685 * @since 11 686 */ 687 /** 688 * P12 format certificate 689 * @syscap SystemCapability.Communication.NetStack 690 * @crossplatform 691 * @since 12 692 */ 693 P12 = 'P12' 694 } 695 696 /** 697 * The clientCert field of the client certificate, which includes 4 attributes: 698 * client certificate (cert), client certificate type (certType), certificate private key (key), and passphrase (keyPassword). 699 * @interface ClientCert 700 * @syscap SystemCapability.Communication.NetStack 701 * @since 11 702 */ 703 /** 704 * The clientCert field of the client certificate, which includes 4 attributes: 705 * client certificate (cert), client certificate type (certType), certificate private key (key), and passphrase (keyPassword). 706 * @interface ClientCert 707 * @syscap SystemCapability.Communication.NetStack 708 * @crossplatform 709 * @since 12 710 */ 711 export interface ClientCert { 712 /** 713 * The path to the client certificate file. 714 * @type {string} 715 * @syscap SystemCapability.Communication.NetStack 716 * @since 11 717 */ 718 /** 719 * The path to the client certificate file. 720 * @type {string} 721 * @syscap SystemCapability.Communication.NetStack 722 * @crossplatform 723 * @since 12 724 */ 725 certPath: string; 726 727 /** 728 * The type of the client certificate. 729 * @type {?CertType} 730 * @syscap SystemCapability.Communication.NetStack 731 * @since 11 732 */ 733 /** 734 * The type of the client certificate. 735 * @type {?CertType} 736 * @syscap SystemCapability.Communication.NetStack 737 * @crossplatform 738 * @since 12 739 */ 740 certType?: CertType; 741 742 /** 743 * The path of the client certificate private key file. 744 * @type {string} 745 * @syscap SystemCapability.Communication.NetStack 746 * @since 11 747 */ 748 /** 749 * The path of the client certificate private key file. 750 * @type {string} 751 * @syscap SystemCapability.Communication.NetStack 752 * @crossplatform 753 * @since 12 754 */ 755 keyPath: string; 756 757 /** 758 * Password required to use the client certificate private key. 759 * @type {?string} 760 * @syscap SystemCapability.Communication.NetStack 761 * @since 11 762 */ 763 /** 764 * Password required to use the client certificate private key. 765 * @type {?string} 766 * @syscap SystemCapability.Communication.NetStack 767 * @crossplatform 768 * @since 12 769 */ 770 keyPassword?: string; 771 } 772 773 /** 774 * Certificate pinning option. 775 * @interface CertificatePinning 776 * @syscap SystemCapability.Communication.NetStack 777 * @since 12 778 */ 779 interface CertificatePinning { 780 /** 781 * Public key hash. 782 * @type {string} 783 * @syscap SystemCapability.Communication.NetStack 784 * @since 12 785 */ 786 publicKeyHash: string; 787 /** 788 * Certificate public key hash algorithm. 789 * @type {'SHA-256'} 790 * @syscap SystemCapability.Communication.NetStack 791 * @since 12 792 */ 793 hashAlgorithm: 'SHA-256'; 794 } 795 796 /** 797 * <p>Defines an HTTP request task. Before invoking APIs provided by HttpRequest, 798 * you must call createHttp() to create an HttpRequestTask object.</p> 799 * @interface HttpRequest 800 * @syscap SystemCapability.Communication.NetStack 801 * @since 6 802 */ 803 /** 804 * <p>Defines an HTTP request task. Before invoking APIs provided by HttpRequest, 805 * you must call createHttp() to create an HttpRequestTask object.</p> 806 * @interface HttpRequest 807 * @syscap SystemCapability.Communication.NetStack 808 * @crossplatform 809 * @since 10 810 */ 811 /** 812 * <p>Defines an HTTP request task. Before invoking APIs provided by HttpRequest, 813 * you must call createHttp() to create an HttpRequestTask object.</p> 814 * @interface HttpRequest 815 * @syscap SystemCapability.Communication.NetStack 816 * @crossplatform 817 * @atomicservice 818 * @since 11 819 */ 820 export interface HttpRequest { 821 /** 822 * Initiates an HTTP request to a given URL. 823 * @permission ohos.permission.INTERNET 824 * @param { string } url - URL for initiating an HTTP request. 825 * @param { AsyncCallback<HttpResponse> } callback - the callback of request. 826 * @throws { BusinessError } 401 - Parameter error. 827 * @throws { BusinessError } 201 - Permission denied. 828 * @throws { BusinessError } 2300001 - Unsupported protocol. 829 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 830 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 831 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 832 * @throws { BusinessError } 2300007 - Failed to connect to the server. 833 * @throws { BusinessError } 2300008 - Invalid server response. 834 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 835 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 836 * @throws { BusinessError } 2300018 - Transferred a partial file. 837 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 838 * @throws { BusinessError } 2300025 - Upload failed. 839 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 840 * @throws { BusinessError } 2300027 - Out of memory. 841 * @throws { BusinessError } 2300028 - Operation timeout. 842 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 843 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 844 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 845 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 846 * @throws { BusinessError } 2300058 - Local SSL certificate error. 847 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 848 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 849 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 850 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 851 * @throws { BusinessError } 2300070 - Remote disk full. 852 * @throws { BusinessError } 2300073 - Remote file already exists. 853 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 854 * @throws { BusinessError } 2300078 - Remote file not found. 855 * @throws { BusinessError } 2300094 - Authentication error. 856 * @throws { BusinessError } 2300999 - Unknown error. 857 * @syscap SystemCapability.Communication.NetStack 858 * @since 6 859 */ 860 /** 861 * Initiates an HTTP request to a given URL. 862 * @permission ohos.permission.INTERNET 863 * @param { string } url - URL for initiating an HTTP request. 864 * @param { AsyncCallback<HttpResponse> } callback - the callback of request. 865 * @throws { BusinessError } 401 - Parameter error. 866 * @throws { BusinessError } 201 - Permission denied. 867 * @throws { BusinessError } 2300001 - Unsupported protocol. 868 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 869 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 870 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 871 * @throws { BusinessError } 2300007 - Failed to connect to the server. 872 * @throws { BusinessError } 2300008 - Invalid server response. 873 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 874 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 875 * @throws { BusinessError } 2300018 - Transferred a partial file. 876 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 877 * @throws { BusinessError } 2300025 - Upload failed. 878 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 879 * @throws { BusinessError } 2300027 - Out of memory. 880 * @throws { BusinessError } 2300028 - Operation timeout. 881 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 882 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 883 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 884 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 885 * @throws { BusinessError } 2300058 - Local SSL certificate error. 886 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 887 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 888 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 889 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 890 * @throws { BusinessError } 2300070 - Remote disk full. 891 * @throws { BusinessError } 2300073 - Remote file already exists. 892 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 893 * @throws { BusinessError } 2300078 - Remote file not found. 894 * @throws { BusinessError } 2300094 - Authentication error. 895 * @throws { BusinessError } 2300999 - Unknown error. 896 * @syscap SystemCapability.Communication.NetStack 897 * @crossplatform 898 * @since 10 899 */ 900 /** 901 * Initiates an HTTP request to a given URL. 902 * @permission ohos.permission.INTERNET 903 * @param { string } url - URL for initiating an HTTP request. 904 * @param { AsyncCallback<HttpResponse> } callback - the callback of request. 905 * @throws { BusinessError } 401 - Parameter error. 906 * @throws { BusinessError } 201 - Permission denied. 907 * @throws { BusinessError } 2300001 - Unsupported protocol. 908 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 909 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 910 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 911 * @throws { BusinessError } 2300007 - Failed to connect to the server. 912 * @throws { BusinessError } 2300008 - Invalid server response. 913 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 914 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 915 * @throws { BusinessError } 2300018 - Transferred a partial file. 916 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 917 * @throws { BusinessError } 2300025 - Upload failed. 918 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 919 * @throws { BusinessError } 2300027 - Out of memory. 920 * @throws { BusinessError } 2300028 - Operation timeout. 921 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 922 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 923 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 924 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 925 * @throws { BusinessError } 2300058 - Local SSL certificate error. 926 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 927 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 928 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 929 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 930 * @throws { BusinessError } 2300070 - Remote disk full. 931 * @throws { BusinessError } 2300073 - Remote file already exists. 932 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 933 * @throws { BusinessError } 2300078 - Remote file not found. 934 * @throws { BusinessError } 2300094 - Authentication error. 935 * @throws { BusinessError } 2300999 - Unknown error. 936 * @syscap SystemCapability.Communication.NetStack 937 * @crossplatform 938 * @atomicservice 939 * @since 11 940 */ 941 request(url: string, callback: AsyncCallback<HttpResponse>): void; 942 943 /** 944 * Initiates an HTTP request to a given URL. 945 * @permission ohos.permission.INTERNET 946 * @param { string } url - URL for initiating an HTTP request. 947 * @param { HttpRequestOptions } options - Optional parameters {@link HttpRequestOptions}. 948 * @param { AsyncCallback<HttpResponse> } callback - the callback of request.. 949 * @throws { BusinessError } 401 - Parameter error. 950 * @throws { BusinessError } 201 - Permission denied. 951 * @throws { BusinessError } 2300001 - Unsupported protocol. 952 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 953 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 954 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 955 * @throws { BusinessError } 2300007 - Failed to connect to the server. 956 * @throws { BusinessError } 2300008 - Invalid server response. 957 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 958 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 959 * @throws { BusinessError } 2300018 - Transferred a partial file. 960 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 961 * @throws { BusinessError } 2300025 - Upload failed. 962 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 963 * @throws { BusinessError } 2300027 - Out of memory. 964 * @throws { BusinessError } 2300028 - Operation timeout. 965 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 966 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 967 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 968 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 969 * @throws { BusinessError } 2300058 - Local SSL certificate error. 970 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 971 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 972 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 973 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 974 * @throws { BusinessError } 2300070 - Remote disk full. 975 * @throws { BusinessError } 2300073 - Remote file already exists. 976 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 977 * @throws { BusinessError } 2300078 - Remote file not found. 978 * @throws { BusinessError } 2300094 - Authentication error. 979 * @throws { BusinessError } 2300999 - Unknown error. 980 * @syscap SystemCapability.Communication.NetStack 981 * @since 6 982 */ 983 /** 984 * Initiates an HTTP request to a given URL. 985 * @permission ohos.permission.INTERNET 986 * @param { string } url - URL for initiating an HTTP request. 987 * @param { HttpRequestOptions } options - Optional parameters {@link HttpRequestOptions}. 988 * @param { AsyncCallback<HttpResponse> } callback - the callback of request. 989 * @throws { BusinessError } 401 - Parameter error. 990 * @throws { BusinessError } 201 - Permission denied. 991 * @throws { BusinessError } 2300001 - Unsupported protocol. 992 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 993 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 994 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 995 * @throws { BusinessError } 2300007 - Failed to connect to the server. 996 * @throws { BusinessError } 2300008 - Invalid server response. 997 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 998 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 999 * @throws { BusinessError } 2300018 - Transferred a partial file. 1000 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 1001 * @throws { BusinessError } 2300025 - Upload failed. 1002 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 1003 * @throws { BusinessError } 2300027 - Out of memory. 1004 * @throws { BusinessError } 2300028 - Operation timeout. 1005 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 1006 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 1007 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 1008 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 1009 * @throws { BusinessError } 2300058 - Local SSL certificate error. 1010 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 1011 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 1012 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 1013 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 1014 * @throws { BusinessError } 2300070 - Remote disk full. 1015 * @throws { BusinessError } 2300073 - Remote file already exists. 1016 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 1017 * @throws { BusinessError } 2300078 - Remote file not found. 1018 * @throws { BusinessError } 2300094 - Authentication error. 1019 * @throws { BusinessError } 2300999 - Unknown error. 1020 * @syscap SystemCapability.Communication.NetStack 1021 * @crossplatform 1022 * @since 10 1023 */ 1024 /** 1025 * Initiates an HTTP request to a given URL. 1026 * @permission ohos.permission.INTERNET 1027 * @param { string } url - URL for initiating an HTTP request. 1028 * @param { HttpRequestOptions } options - Optional parameters {@link HttpRequestOptions}. 1029 * @param { AsyncCallback<HttpResponse> } callback - the callback of request. 1030 * @throws { BusinessError } 401 - Parameter error. 1031 * @throws { BusinessError } 201 - Permission denied. 1032 * @throws { BusinessError } 2300001 - Unsupported protocol. 1033 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 1034 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 1035 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 1036 * @throws { BusinessError } 2300007 - Failed to connect to the server. 1037 * @throws { BusinessError } 2300008 - Invalid server response. 1038 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 1039 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 1040 * @throws { BusinessError } 2300018 - Transferred a partial file. 1041 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 1042 * @throws { BusinessError } 2300025 - Upload failed. 1043 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 1044 * @throws { BusinessError } 2300027 - Out of memory. 1045 * @throws { BusinessError } 2300028 - Operation timeout. 1046 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 1047 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 1048 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 1049 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 1050 * @throws { BusinessError } 2300058 - Local SSL certificate error. 1051 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 1052 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 1053 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 1054 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 1055 * @throws { BusinessError } 2300070 - Remote disk full. 1056 * @throws { BusinessError } 2300073 - Remote file already exists. 1057 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 1058 * @throws { BusinessError } 2300078 - Remote file not found. 1059 * @throws { BusinessError } 2300094 - Authentication error. 1060 * @throws { BusinessError } 2300999 - Unknown error. 1061 * @syscap SystemCapability.Communication.NetStack 1062 * @crossplatform 1063 * @atomicservice 1064 * @since 11 1065 */ 1066 request(url: string, options: HttpRequestOptions, callback: AsyncCallback<HttpResponse>): void; 1067 1068 /** 1069 * Initiates an HTTP request to a given URL. 1070 * @permission ohos.permission.INTERNET 1071 * @param { string } url - URL for initiating an HTTP request. 1072 * @param { HttpRequestOptions } [options] - Optional parameters {@link HttpRequestOptions}. 1073 * @returns { Promise<HttpResponse> } The promise returned by the function. 1074 * @throws { BusinessError } 401 - Parameter error. 1075 * @throws { BusinessError } 201 - Permission denied. 1076 * @throws { BusinessError } 2300001 - Unsupported protocol. 1077 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 1078 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 1079 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 1080 * @throws { BusinessError } 2300007 - Failed to connect to the server. 1081 * @throws { BusinessError } 2300008 - Invalid server response. 1082 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 1083 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 1084 * @throws { BusinessError } 2300018 - Transferred a partial file. 1085 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 1086 * @throws { BusinessError } 2300025 - Upload failed. 1087 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 1088 * @throws { BusinessError } 2300027 - Out of memory. 1089 * @throws { BusinessError } 2300028 - Operation timeout. 1090 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 1091 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 1092 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 1093 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 1094 * @throws { BusinessError } 2300058 - Local SSL certificate error. 1095 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 1096 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 1097 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 1098 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 1099 * @throws { BusinessError } 2300070 - Remote disk full. 1100 * @throws { BusinessError } 2300073 - Remote file already exists. 1101 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 1102 * @throws { BusinessError } 2300078 - Remote file not found. 1103 * @throws { BusinessError } 2300094 - Authentication error. 1104 * @throws { BusinessError } 2300999 - Unknown error. 1105 * @syscap SystemCapability.Communication.NetStack 1106 * @since 6 1107 */ 1108 /** 1109 * Initiates an HTTP request to a given URL. 1110 * @permission ohos.permission.INTERNET 1111 * @param { string } url - URL for initiating an HTTP request. 1112 * @param { HttpRequestOptions } [options] - Optional parameters {@link HttpRequestOptions}. 1113 * @returns { Promise<HttpResponse> } The promise returned by the function. 1114 * @throws { BusinessError } 401 - Parameter error. 1115 * @throws { BusinessError } 201 - Permission denied. 1116 * @throws { BusinessError } 2300001 - Unsupported protocol. 1117 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 1118 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 1119 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 1120 * @throws { BusinessError } 2300007 - Failed to connect to the server. 1121 * @throws { BusinessError } 2300008 - Invalid server response. 1122 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 1123 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 1124 * @throws { BusinessError } 2300018 - Transferred a partial file. 1125 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 1126 * @throws { BusinessError } 2300025 - Upload failed. 1127 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 1128 * @throws { BusinessError } 2300027 - Out of memory. 1129 * @throws { BusinessError } 2300028 - Operation timeout. 1130 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 1131 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 1132 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 1133 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 1134 * @throws { BusinessError } 2300058 - Local SSL certificate error. 1135 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 1136 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 1137 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 1138 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 1139 * @throws { BusinessError } 2300070 - Remote disk full. 1140 * @throws { BusinessError } 2300073 - Remote file already exists. 1141 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 1142 * @throws { BusinessError } 2300078 - Remote file not found. 1143 * @throws { BusinessError } 2300094 - Authentication error. 1144 * @throws { BusinessError } 2300999 - Unknown error. 1145 * @syscap SystemCapability.Communication.NetStack 1146 * @crossplatform 1147 * @since 10 1148 */ 1149 /** 1150 * Initiates an HTTP request to a given URL. 1151 * @permission ohos.permission.INTERNET 1152 * @param { string } url - URL for initiating an HTTP request. 1153 * @param { HttpRequestOptions } [options] - Optional parameters {@link HttpRequestOptions}. 1154 * @returns { Promise<HttpResponse> } The promise returned by the function. 1155 * @throws { BusinessError } 401 - Parameter error. 1156 * @throws { BusinessError } 201 - Permission denied. 1157 * @throws { BusinessError } 2300001 - Unsupported protocol. 1158 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 1159 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 1160 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 1161 * @throws { BusinessError } 2300007 - Failed to connect to the server. 1162 * @throws { BusinessError } 2300008 - Invalid server response. 1163 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 1164 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 1165 * @throws { BusinessError } 2300018 - Transferred a partial file. 1166 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 1167 * @throws { BusinessError } 2300025 - Upload failed. 1168 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 1169 * @throws { BusinessError } 2300027 - Out of memory. 1170 * @throws { BusinessError } 2300028 - Operation timeout. 1171 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 1172 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 1173 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 1174 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 1175 * @throws { BusinessError } 2300058 - Local SSL certificate error. 1176 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 1177 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 1178 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 1179 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 1180 * @throws { BusinessError } 2300070 - Remote disk full. 1181 * @throws { BusinessError } 2300073 - Remote file already exists. 1182 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 1183 * @throws { BusinessError } 2300078 - Remote file not found. 1184 * @throws { BusinessError } 2300094 - Authentication error. 1185 * @throws { BusinessError } 2300999 - Unknown error. 1186 * @syscap SystemCapability.Communication.NetStack 1187 * @crossplatform 1188 * @atomicservice 1189 * @since 11 1190 */ 1191 request(url: string, options?: HttpRequestOptions): Promise<HttpResponse>; 1192 1193 /** 1194 * Initiates an HTTP request to a given URL, applicable to scenarios where http response supports streaming. 1195 * @permission ohos.permission.INTERNET 1196 * @param { string } url - URL for initiating an HTTP request. 1197 * @param { AsyncCallback<number> } callback - Returns the callback of requestInStream {@link ResponseCode}, 1198 * should use on_headersReceive and on_dataReceive to get http response. 1199 * @throws { BusinessError } 401 - Parameter error. 1200 * @throws { BusinessError } 201 - Permission denied. 1201 * @throws { BusinessError } 2300001 - Unsupported protocol. 1202 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 1203 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 1204 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 1205 * @throws { BusinessError } 2300007 - Failed to connect to the server. 1206 * @throws { BusinessError } 2300008 - Invalid server response. 1207 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 1208 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 1209 * @throws { BusinessError } 2300018 - Transferred a partial file. 1210 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 1211 * @throws { BusinessError } 2300025 - Upload failed. 1212 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 1213 * @throws { BusinessError } 2300027 - Out of memory. 1214 * @throws { BusinessError } 2300028 - Operation timeout. 1215 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 1216 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 1217 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 1218 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 1219 * @throws { BusinessError } 2300058 - Local SSL certificate error. 1220 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 1221 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 1222 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 1223 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 1224 * @throws { BusinessError } 2300070 - Remote disk full. 1225 * @throws { BusinessError } 2300073 - Remote file already exists. 1226 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 1227 * @throws { BusinessError } 2300078 - Remote file not found. 1228 * @throws { BusinessError } 2300094 - Authentication error. 1229 * @throws { BusinessError } 2300999 - Unknown error. 1230 * @syscap SystemCapability.Communication.NetStack 1231 * @since 10 1232 */ 1233 requestInStream(url: string, callback: AsyncCallback<number>): void; 1234 1235 /** 1236 * Initiates an HTTP request to a given URL, applicable to scenarios where http response supports streaming. 1237 * @permission ohos.permission.INTERNET 1238 * @param { string } url - URL for initiating an HTTP request. 1239 * @param { HttpRequestOptions } options - Optional parameters {@link HttpRequestOptions}. 1240 * @param { AsyncCallback<number> } callback - the callback of requestInStream. 1241 * @throws { BusinessError } 401 - Parameter error. 1242 * @throws { BusinessError } 201 - Permission denied. 1243 * @throws { BusinessError } 2300001 - Unsupported protocol. 1244 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 1245 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 1246 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 1247 * @throws { BusinessError } 2300007 - Failed to connect to the server. 1248 * @throws { BusinessError } 2300008 - Invalid server response. 1249 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 1250 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 1251 * @throws { BusinessError } 2300018 - Transferred a partial file. 1252 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 1253 * @throws { BusinessError } 2300025 - Upload failed. 1254 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 1255 * @throws { BusinessError } 2300027 - Out of memory. 1256 * @throws { BusinessError } 2300028 - Operation timeout. 1257 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 1258 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 1259 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 1260 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 1261 * @throws { BusinessError } 2300058 - Local SSL certificate error. 1262 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 1263 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 1264 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 1265 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 1266 * @throws { BusinessError } 2300070 - Remote disk full. 1267 * @throws { BusinessError } 2300073 - Remote file already exists. 1268 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 1269 * @throws { BusinessError } 2300078 - Remote file not found. 1270 * @throws { BusinessError } 2300094 - Authentication error. 1271 * @throws { BusinessError } 2300999 - Unknown error. 1272 * @syscap SystemCapability.Communication.NetStack 1273 * @since 10 1274 */ 1275 requestInStream(url: string, options: HttpRequestOptions, callback: AsyncCallback<number>): void; 1276 1277 /** 1278 * Initiates an HTTP request to a given URL, applicable to scenarios where http response supports streaming. 1279 * @permission ohos.permission.INTERNET 1280 * @param { string } url - URL for initiating an HTTP request. 1281 * @param { HttpRequestOptions } [options] - Optional parameters {@link HttpRequestOptions}. 1282 * @returns { Promise<number> } the promise returned by the function. 1283 * @throws { BusinessError } 401 - Parameter error. 1284 * @throws { BusinessError } 201 - Permission denied. 1285 * @throws { BusinessError } 2300001 - Unsupported protocol. 1286 * @throws { BusinessError } 2300003 - Invalid URL format or missing URL. 1287 * @throws { BusinessError } 2300005 - Failed to resolve the proxy name. 1288 * @throws { BusinessError } 2300006 - Failed to resolve the host name. 1289 * @throws { BusinessError } 2300007 - Failed to connect to the server. 1290 * @throws { BusinessError } 2300008 - Invalid server response. 1291 * @throws { BusinessError } 2300009 - Access to the remote resource denied. 1292 * @throws { BusinessError } 2300016 - Error in the HTTP2 framing layer. 1293 * @throws { BusinessError } 2300018 - Transferred a partial file. 1294 * @throws { BusinessError } 2300023 - Failed to write the received data to the disk or application. 1295 * @throws { BusinessError } 2300025 - Upload failed. 1296 * @throws { BusinessError } 2300026 - Failed to open or read local data from the file or application. 1297 * @throws { BusinessError } 2300027 - Out of memory. 1298 * @throws { BusinessError } 2300028 - Operation timeout. 1299 * @throws { BusinessError } 2300047 - The number of redirections reaches the maximum allowed. 1300 * @throws { BusinessError } 2300052 - The server returned nothing (no header or data). 1301 * @throws { BusinessError } 2300055 - Failed to send data to the peer. 1302 * @throws { BusinessError } 2300056 - Failed to receive data from the peer. 1303 * @throws { BusinessError } 2300058 - Local SSL certificate error. 1304 * @throws { BusinessError } 2300059 - The specified SSL cipher cannot be used. 1305 * @throws { BusinessError } 2300060 - Invalid SSL peer certificate or SSH remote key. 1306 * @throws { BusinessError } 2300061 - Invalid HTTP encoding format. 1307 * @throws { BusinessError } 2300063 - Maximum file size exceeded. 1308 * @throws { BusinessError } 2300070 - Remote disk full. 1309 * @throws { BusinessError } 2300073 - Remote file already exists. 1310 * @throws { BusinessError } 2300077 - The SSL CA certificate does not exist or is inaccessible. 1311 * @throws { BusinessError } 2300078 - Remote file not found. 1312 * @throws { BusinessError } 2300094 - Authentication error. 1313 * @throws { BusinessError } 2300999 - Unknown error. 1314 * @syscap SystemCapability.Communication.NetStack 1315 * @since 10 1316 */ 1317 requestInStream(url: string, options?: HttpRequestOptions): Promise<number>; 1318 1319 /** 1320 * Destroys an HTTP request. 1321 * @syscap SystemCapability.Communication.NetStack 1322 * @since 6 1323 */ 1324 /** 1325 * Destroys an HTTP request. 1326 * @syscap SystemCapability.Communication.NetStack 1327 * @crossplatform 1328 * @since 10 1329 */ 1330 /** 1331 * Destroys an HTTP request. 1332 * @syscap SystemCapability.Communication.NetStack 1333 * @crossplatform 1334 * @atomicservice 1335 * @since 11 1336 */ 1337 destroy(): void; 1338 1339 /** 1340 * Registers an observer for HTTP Response Header events. 1341 * @param { "headerReceive" } type - Indicates Event name. 1342 * @param { AsyncCallback<Object> } callback - the callback used to return the result. 1343 * @syscap SystemCapability.Communication.NetStack 1344 * @since 6 1345 * @deprecated since 8 1346 * @useinstead on_headersReceive 1347 */ 1348 on(type: "headerReceive", callback: AsyncCallback<Object>): void; 1349 1350 /** 1351 * Unregisters the observer for HTTP Response Header events. 1352 * @param { "headerReceive" } type - Indicates Event name. 1353 * @param { AsyncCallback<Object> } [callback] - the callback used to return the result. 1354 * @syscap SystemCapability.Communication.NetStack 1355 * @since 6 1356 * @deprecated since 8 1357 * @useinstead off_headersReceive 1358 */ 1359 off(type: "headerReceive", callback?: AsyncCallback<Object>): void; 1360 1361 /** 1362 * Registers an observer for HTTP Response Header events. 1363 * @param { "headersReceive" } type - Indicates Event name. 1364 * @param { Callback<Object> } callback - the callback used to return the result. 1365 * @syscap SystemCapability.Communication.NetStack 1366 * @since 8 1367 */ 1368 /** 1369 * Registers an observer for HTTP Response Header events. 1370 * @param { "headersReceive" } type - Indicates Event name. 1371 * @param { Callback<Object> } callback - the callback used to return the result. 1372 * @syscap SystemCapability.Communication.NetStack 1373 * @crossplatform 1374 * @since 10 1375 */ 1376 /** 1377 * Registers an observer for HTTP Response Header events. 1378 * @param { "headersReceive" } type - Indicates Event name. 1379 * @param { Callback<Object> } callback - the callback used to return the result. 1380 * @syscap SystemCapability.Communication.NetStack 1381 * @crossplatform 1382 * @atomicservice 1383 * @since 11 1384 */ 1385 on(type: "headersReceive", callback: Callback<Object>): void; 1386 1387 /** 1388 * Unregisters the observer for HTTP Response Header events. 1389 * @param { "headersReceive" } type - Indicates Event name. 1390 * @param { Callback<Object> } callback - the callback used to return the result. 1391 * @syscap SystemCapability.Communication.NetStack 1392 * @since 8 1393 */ 1394 /** 1395 * Unregisters the observer for HTTP Response Header events. 1396 * @param { "headersReceive" } type - Indicates Event name. 1397 * @param { Callback<Object> } callback - the callback used to return the result. 1398 * @syscap SystemCapability.Communication.NetStack 1399 * @crossplatform 1400 * @since 10 1401 */ 1402 /** 1403 * Unregisters the observer for HTTP Response Header events. 1404 * @param { "headersReceive" } type - Indicates Event name. 1405 * @param { Callback<Object> } [callback] - the callback used to return the result. 1406 * @syscap SystemCapability.Communication.NetStack 1407 * @crossplatform 1408 * @atomicservice 1409 * @since 11 1410 */ 1411 off(type: "headersReceive", callback?: Callback<Object>): void; 1412 1413 /** 1414 * Registers a one-time observer for HTTP Response Header events. 1415 * @param { "headersReceive" } type - Indicates Event name. 1416 * @param { Callback<Object> } callback - the callback used to return the result. 1417 * @syscap SystemCapability.Communication.NetStack 1418 * @since 8 1419 */ 1420 /** 1421 * Registers a one-time observer for HTTP Response Header events. 1422 * @param { "headersReceive" } type - Indicates Event name. 1423 * @param { Callback<Object> } callback - the callback used to return the result. 1424 * @syscap SystemCapability.Communication.NetStack 1425 * @crossplatform 1426 * @since 10 1427 */ 1428 once(type: "headersReceive", callback: Callback<Object>): void; 1429 1430 /** 1431 * Registers an observer for receiving HTTP Response data events continuously. 1432 * @param { "dataReceive" } type - Indicates Event name. 1433 * @param { Callback<ArrayBuffer> } callback - the callback used to return the result. 1434 * @syscap SystemCapability.Communication.NetStack 1435 * @since 10 1436 */ 1437 on(type: "dataReceive", callback: Callback<ArrayBuffer>): void; 1438 1439 /** 1440 * Unregisters an observer for receiving HTTP Response data events continuously. 1441 * @param { "dataReceive" } type - Indicates Event name. 1442 * @param { Callback<ArrayBuffer> } [callback] - the callback used to return the result. 1443 * @syscap SystemCapability.Communication.NetStack 1444 * @since 10 1445 */ 1446 off(type: "dataReceive", callback?: Callback<ArrayBuffer>): void; 1447 1448 /** 1449 * Registers an observer for receiving HTTP Response data ends events. 1450 * @param { "dataEnd" } type - Indicates Event name. 1451 * @param { Callback<void> } callback - the callback used to return the result. 1452 * @syscap SystemCapability.Communication.NetStack 1453 * @since 10 1454 */ 1455 on(type: "dataEnd", callback: Callback<void>): void; 1456 1457 /** 1458 * Unregisters an observer for receiving HTTP Response data ends events. 1459 * @param { "dataEnd" } type - Indicates Event name. 1460 * @param { Callback<void> } [callback] - the callback used to return the result. 1461 * @syscap SystemCapability.Communication.NetStack 1462 * @since 10 1463 */ 1464 off(type: "dataEnd", callback?: Callback<void>): void; 1465 1466 /** 1467 * Registers an observer for progress of receiving HTTP Response data events. 1468 * @param { 'dataReceiveProgress' } type - Indicates Event name. 1469 * @param { Callback<{ receiveSize: number, totalSize: number }> } callback - the callback used to return the result. 1470 * @syscap SystemCapability.Communication.NetStack 1471 * @since 10 1472 */ 1473 /** 1474 * Registers an observer for progress of receiving HTTP Response data events. 1475 * @param { 'dataReceiveProgress' } type - Indicates Event name. 1476 * @param { Callback<DataReceiveProgressInfo> } callback - the callback used to return the result. 1477 * @syscap SystemCapability.Communication.NetStack 1478 * @since 11 1479 */ 1480 /** 1481 * Registers an observer for progress of receiving HTTP Response data events. 1482 * @param { 'dataReceiveProgress' } type - Indicates Event name. 1483 * @param { Callback<DataReceiveProgressInfo> } callback - the callback used to return the result. 1484 * @syscap SystemCapability.Communication.NetStack 1485 * @crossplatform 1486 * @since 12 1487 */ 1488 on(type: 'dataReceiveProgress', callback: Callback<DataReceiveProgressInfo>): void; 1489 1490 /** 1491 * Unregisters an observer for progress of receiving HTTP Response data events. 1492 * @param { 'dataReceiveProgress' } type - Indicates Event name. 1493 * @param { Callback<{ receiveSize: number, totalSize: number }> } [callback] - the callback used to return the result. 1494 * @syscap SystemCapability.Communication.NetStack 1495 * @since 10 1496 */ 1497 /** 1498 * Unregisters an observer for progress of receiving HTTP Response data events. 1499 * @param { 'dataReceiveProgress' } type - Indicates Event name. 1500 * @param { Callback<DataReceiveProgressInfo> } callback - the callback used to return the result. 1501 * @syscap SystemCapability.Communication.NetStack 1502 * @since 11 1503 */ 1504 /** 1505 * Unregisters an observer for progress of receiving HTTP Response data events. 1506 * @param { 'dataReceiveProgress' } type - Indicates Event name. 1507 * @param { Callback<DataReceiveProgressInfo> } callback - the callback used to return the result. 1508 * @syscap SystemCapability.Communication.NetStack 1509 * @crossplatform 1510 * @since 12 1511 */ 1512 off(type: 'dataReceiveProgress', callback?: Callback<DataReceiveProgressInfo>): void; 1513 1514 /** 1515 * Registers an observer for progress of sendSize HTTP Response data events. 1516 * @param { 'dataSendProgress' } type - Indicates Event name. 1517 * @param { Callback<DataSendProgressInfo> } callback - the callback of on. 1518 * @syscap SystemCapability.Communication.NetStack 1519 * @since 11 1520 */ 1521 /** 1522 * Registers an observer for progress of sendSize HTTP Response data events. 1523 * @param { 'dataSendProgress' } type - Indicates Event name. 1524 * @param { Callback<DataSendProgressInfo> } callback - the callback of on. 1525 * @syscap SystemCapability.Communication.NetStack 1526 * @crossplatform 1527 * @since 12 1528 */ 1529 on(type: 'dataSendProgress', callback: Callback<DataSendProgressInfo>): void 1530 1531 /** 1532 * Unregisters an observer for progress of sendSize HTTP Response data events. 1533 * @param { 'dataSendProgress' } type - Indicates Event name. 1534 * @param { Callback<DataSendProgressInfo> } [callback] - the callback of off. 1535 * @syscap SystemCapability.Communication.NetStack 1536 * @since 11 1537 */ 1538 /** 1539 * Unregisters an observer for progress of sendSize HTTP Response data events. 1540 * @param { 'dataSendProgress' } type - Indicates Event name. 1541 * @param { Callback<DataSendProgressInfo> } [callback] - the callback of off. 1542 * @syscap SystemCapability.Communication.NetStack 1543 * @crossplatform 1544 * @since 12 1545 */ 1546 off(type: 'dataSendProgress', callback?: Callback<DataSendProgressInfo>): void 1547 } 1548 1549 /** 1550 * Defines an HTTP request method. 1551 * @enum {string} 1552 * @syscap SystemCapability.Communication.NetStack 1553 * @since 6 1554 */ 1555 /** 1556 * Defines an HTTP request method. 1557 * @enum {string} 1558 * @syscap SystemCapability.Communication.NetStack 1559 * @crossplatform 1560 * @since 10 1561 */ 1562 /** 1563 * Defines an HTTP request method. 1564 * @enum {string} 1565 * @syscap SystemCapability.Communication.NetStack 1566 * @crossplatform 1567 * @atomicservice 1568 * @since 11 1569 */ 1570 export enum RequestMethod { 1571 /** 1572 * OPTIONS method. 1573 * @syscap SystemCapability.Communication.NetStack 1574 * @since 6 1575 */ 1576 /** 1577 * OPTIONS method. 1578 * @syscap SystemCapability.Communication.NetStack 1579 * @crossplatform 1580 * @since 10 1581 */ 1582 /** 1583 * OPTIONS method. 1584 * @syscap SystemCapability.Communication.NetStack 1585 * @crossplatform 1586 * @atomicservice 1587 * @since 11 1588 */ 1589 OPTIONS = "OPTIONS", 1590 1591 /** 1592 * GET method. 1593 * @syscap SystemCapability.Communication.NetStack 1594 * @since 6 1595 */ 1596 /** 1597 * GET method. 1598 * @syscap SystemCapability.Communication.NetStack 1599 * @crossplatform 1600 * @since 10 1601 */ 1602 /** 1603 * GET method. 1604 * @syscap SystemCapability.Communication.NetStack 1605 * @crossplatform 1606 * @atomicservice 1607 * @since 11 1608 */ 1609 GET = "GET", 1610 1611 /** 1612 * HEAD method. 1613 * @syscap SystemCapability.Communication.NetStack 1614 * @since 6 1615 */ 1616 /** 1617 * HEAD method. 1618 * @syscap SystemCapability.Communication.NetStack 1619 * @crossplatform 1620 * @since 10 1621 */ 1622 /** 1623 * HEAD method. 1624 * @syscap SystemCapability.Communication.NetStack 1625 * @crossplatform 1626 * @atomicservice 1627 * @since 11 1628 */ 1629 HEAD = "HEAD", 1630 1631 /** 1632 * POST method. 1633 * @syscap SystemCapability.Communication.NetStack 1634 * @since 6 1635 */ 1636 /** 1637 * POST method. 1638 * @syscap SystemCapability.Communication.NetStack 1639 * @crossplatform 1640 * @since 10 1641 */ 1642 /** 1643 * POST method. 1644 * @syscap SystemCapability.Communication.NetStack 1645 * @crossplatform 1646 * @atomicservice 1647 * @since 11 1648 */ 1649 POST = "POST", 1650 1651 /** 1652 * PUT method. 1653 * @syscap SystemCapability.Communication.NetStack 1654 * @since 6 1655 */ 1656 /** 1657 * PUT method. 1658 * @syscap SystemCapability.Communication.NetStack 1659 * @crossplatform 1660 * @since 10 1661 */ 1662 /** 1663 * PUT method. 1664 * @syscap SystemCapability.Communication.NetStack 1665 * @crossplatform 1666 * @atomicservice 1667 * @since 11 1668 */ 1669 PUT = "PUT", 1670 1671 /** 1672 * DELETE method. 1673 * @syscap SystemCapability.Communication.NetStack 1674 * @since 6 1675 */ 1676 /** 1677 * DELETE method. 1678 * @syscap SystemCapability.Communication.NetStack 1679 * @crossplatform 1680 * @since 10 1681 */ 1682 /** 1683 * DELETE method. 1684 * @syscap SystemCapability.Communication.NetStack 1685 * @crossplatform 1686 * @atomicservice 1687 * @since 11 1688 */ 1689 DELETE = "DELETE", 1690 1691 /** 1692 * TRACE method. 1693 * @syscap SystemCapability.Communication.NetStack 1694 * @since 6 1695 */ 1696 /** 1697 * TRACE method. 1698 * @syscap SystemCapability.Communication.NetStack 1699 * @crossplatform 1700 * @since 10 1701 */ 1702 /** 1703 * TRACE method. 1704 * @syscap SystemCapability.Communication.NetStack 1705 * @crossplatform 1706 * @atomicservice 1707 * @since 11 1708 */ 1709 TRACE = "TRACE", 1710 1711 /** 1712 * CONNECT method. 1713 * @syscap SystemCapability.Communication.NetStack 1714 * @since 6 1715 */ 1716 /** 1717 * CONNECT method. 1718 * @syscap SystemCapability.Communication.NetStack 1719 * @crossplatform 1720 * @since 10 1721 */ 1722 /** 1723 * CONNECT method. 1724 * @syscap SystemCapability.Communication.NetStack 1725 * @crossplatform 1726 * @atomicservice 1727 * @since 11 1728 */ 1729 CONNECT = "CONNECT" 1730 } 1731 1732 /** 1733 * Enumerates the response codes for an HTTP request. 1734 * @enum {number} 1735 * @syscap SystemCapability.Communication.NetStack 1736 * @since 6 1737 */ 1738 /** 1739 * Enumerates the response codes for an HTTP request. 1740 * @enum {number} 1741 * @syscap SystemCapability.Communication.NetStack 1742 * @crossplatform 1743 * @since 10 1744 */ 1745 /** 1746 * Enumerates the response codes for an HTTP request. 1747 * @enum {number} 1748 * @syscap SystemCapability.Communication.NetStack 1749 * @crossplatform 1750 * @atomicservice 1751 * @since 11 1752 */ 1753 export enum ResponseCode { 1754 /** 1755 * The request was successful. Typically used for GET and POST requests. 1756 * @syscap SystemCapability.Communication.NetStack 1757 * @since 6 1758 */ 1759 /** 1760 * The request was successful. Typically used for GET and POST requests. 1761 * @syscap SystemCapability.Communication.NetStack 1762 * @crossplatform 1763 * @since 10 1764 */ 1765 /** 1766 * The request was successful. Typically used for GET and POST requests. 1767 * @syscap SystemCapability.Communication.NetStack 1768 * @crossplatform 1769 * @atomicservice 1770 * @since 11 1771 */ 1772 OK = 200, 1773 1774 /** 1775 * Successfully requested and created a new resource. 1776 * @syscap SystemCapability.Communication.NetStack 1777 * @since 6 1778 */ 1779 /** 1780 * Successfully requested and created a new resource. 1781 * @syscap SystemCapability.Communication.NetStack 1782 * @crossplatform 1783 * @since 10 1784 */ 1785 /** 1786 * Successfully requested and created a new resource. 1787 * @syscap SystemCapability.Communication.NetStack 1788 * @crossplatform 1789 * @atomicservice 1790 * @since 11 1791 */ 1792 CREATED, 1793 1794 /** 1795 * The request has been accepted but has not been processed completely. 1796 * @syscap SystemCapability.Communication.NetStack 1797 * @since 6 1798 */ 1799 /** 1800 * The request has been accepted but has not been processed completely. 1801 * @syscap SystemCapability.Communication.NetStack 1802 * @crossplatform 1803 * @since 10 1804 */ 1805 /** 1806 * The request has been accepted but has not been processed completely. 1807 * @syscap SystemCapability.Communication.NetStack 1808 * @crossplatform 1809 * @atomicservice 1810 * @since 11 1811 */ 1812 ACCEPTED, 1813 1814 /** 1815 * Unauthorized information. The request was successful. 1816 * @syscap SystemCapability.Communication.NetStack 1817 * @since 6 1818 */ 1819 /** 1820 * Unauthorized information. The request was successful. 1821 * @syscap SystemCapability.Communication.NetStack 1822 * @crossplatform 1823 * @since 10 1824 */ 1825 /** 1826 * Unauthorized information. The request was successful. 1827 * @syscap SystemCapability.Communication.NetStack 1828 * @crossplatform 1829 * @atomicservice 1830 * @since 11 1831 */ 1832 NOT_AUTHORITATIVE, 1833 1834 /** 1835 * No content. The server successfully processed, but did not return content. 1836 * @syscap SystemCapability.Communication.NetStack 1837 * @since 6 1838 */ 1839 /** 1840 * No content. The server successfully processed, but did not return content. 1841 * @syscap SystemCapability.Communication.NetStack 1842 * @crossplatform 1843 * @since 10 1844 */ 1845 /** 1846 * No content. The server successfully processed, but did not return content. 1847 * @syscap SystemCapability.Communication.NetStack 1848 * @crossplatform 1849 * @atomicservice 1850 * @since 11 1851 */ 1852 NO_CONTENT, 1853 1854 /** 1855 * Reset the content. 1856 * @syscap SystemCapability.Communication.NetStack 1857 * @since 6 1858 */ 1859 /** 1860 * Reset the content. 1861 * @syscap SystemCapability.Communication.NetStack 1862 * @crossplatform 1863 * @since 10 1864 */ 1865 /** 1866 * Reset the content. 1867 * @syscap SystemCapability.Communication.NetStack 1868 * @crossplatform 1869 * @atomicservice 1870 * @since 11 1871 */ 1872 RESET, 1873 1874 /** 1875 * Partial content. The server successfully processed some GET requests. 1876 * @syscap SystemCapability.Communication.NetStack 1877 * @since 6 1878 */ 1879 /** 1880 * Partial content. The server successfully processed some GET requests. 1881 * @syscap SystemCapability.Communication.NetStack 1882 * @crossplatform 1883 * @since 10 1884 */ 1885 /** 1886 * Partial content. The server successfully processed some GET requests. 1887 * @syscap SystemCapability.Communication.NetStack 1888 * @crossplatform 1889 * @atomicservice 1890 * @since 11 1891 */ 1892 PARTIAL, 1893 1894 /** 1895 * Multiple options. 1896 * @syscap SystemCapability.Communication.NetStack 1897 * @since 6 1898 */ 1899 /** 1900 * Multiple options. 1901 * @syscap SystemCapability.Communication.NetStack 1902 * @crossplatform 1903 * @since 10 1904 */ 1905 /** 1906 * Multiple options. 1907 * @syscap SystemCapability.Communication.NetStack 1908 * @crossplatform 1909 * @atomicservice 1910 * @since 11 1911 */ 1912 MULT_CHOICE = 300, 1913 1914 /** 1915 * <p>Permanently move. The requested resource has been permanently moved to a new URI, 1916 * and the returned information will include the new URI. The browser will automatically redirect to the new URI.</p> 1917 * @syscap SystemCapability.Communication.NetStack 1918 * @since 6 1919 */ 1920 /** 1921 * <p>Permanently move. The requested resource has been permanently moved to a new URI, 1922 * and the returned information will include the new URI. The browser will automatically redirect to the new URI.</p> 1923 * @syscap SystemCapability.Communication.NetStack 1924 * @crossplatform 1925 * @since 10 1926 */ 1927 /** 1928 * <p>Permanently move. The requested resource has been permanently moved to a new URI, 1929 * and the returned information will include the new URI. The browser will automatically redirect to the new URI.</p> 1930 * @syscap SystemCapability.Communication.NetStack 1931 * @crossplatform 1932 * @atomicservice 1933 * @since 11 1934 */ 1935 MOVED_PERM, 1936 1937 /** 1938 * Temporary movement. 1939 * @syscap SystemCapability.Communication.NetStack 1940 * @since 6 1941 */ 1942 /** 1943 * Temporary movement. 1944 * @syscap SystemCapability.Communication.NetStack 1945 * @crossplatform 1946 * @since 10 1947 */ 1948 /** 1949 * Temporary movement. 1950 * @syscap SystemCapability.Communication.NetStack 1951 * @crossplatform 1952 * @atomicservice 1953 * @since 11 1954 */ 1955 MOVED_TEMP, 1956 1957 /** 1958 * View other addresses. 1959 * @syscap SystemCapability.Communication.NetStack 1960 * @since 6 1961 */ 1962 /** 1963 * View other addresses. 1964 * @syscap SystemCapability.Communication.NetStack 1965 * @crossplatform 1966 * @since 10 1967 */ 1968 /** 1969 * View other addresses. 1970 * @syscap SystemCapability.Communication.NetStack 1971 * @crossplatform 1972 * @atomicservice 1973 * @since 11 1974 */ 1975 SEE_OTHER, 1976 1977 /** 1978 * Not modified. 1979 * @syscap SystemCapability.Communication.NetStack 1980 * @since 6 1981 */ 1982 /** 1983 * Not modified. 1984 * @syscap SystemCapability.Communication.NetStack 1985 * @crossplatform 1986 * @since 10 1987 */ 1988 /** 1989 * Not modified. 1990 * @syscap SystemCapability.Communication.NetStack 1991 * @crossplatform 1992 * @atomicservice 1993 * @since 11 1994 */ 1995 NOT_MODIFIED, 1996 1997 /** 1998 * Using proxies. 1999 * @syscap SystemCapability.Communication.NetStack 2000 * @since 6 2001 */ 2002 /** 2003 * Using proxies. 2004 * @syscap SystemCapability.Communication.NetStack 2005 * @crossplatform 2006 * @since 10 2007 */ 2008 /** 2009 * Using proxies. 2010 * @syscap SystemCapability.Communication.NetStack 2011 * @crossplatform 2012 * @atomicservice 2013 * @since 11 2014 */ 2015 USE_PROXY, 2016 2017 /** 2018 * The server cannot understand the syntax error error requested by the client. 2019 * @syscap SystemCapability.Communication.NetStack 2020 * @since 6 2021 */ 2022 /** 2023 * The server cannot understand the syntax error error requested by the client. 2024 * @syscap SystemCapability.Communication.NetStack 2025 * @crossplatform 2026 * @since 10 2027 */ 2028 /** 2029 * The server cannot understand the syntax error error requested by the client. 2030 * @syscap SystemCapability.Communication.NetStack 2031 * @crossplatform 2032 * @atomicservice 2033 * @since 11 2034 */ 2035 BAD_REQUEST = 400, 2036 2037 /** 2038 * Request for user authentication. 2039 * @syscap SystemCapability.Communication.NetStack 2040 * @since 6 2041 */ 2042 /** 2043 * Request for user authentication. 2044 * @syscap SystemCapability.Communication.NetStack 2045 * @crossplatform 2046 * @since 10 2047 */ 2048 /** 2049 * Request for user authentication. 2050 * @syscap SystemCapability.Communication.NetStack 2051 * @crossplatform 2052 * @atomicservice 2053 * @since 11 2054 */ 2055 UNAUTHORIZED, 2056 2057 /** 2058 * Reserved for future use. 2059 * @syscap SystemCapability.Communication.NetStack 2060 * @since 6 2061 */ 2062 /** 2063 * Reserved for future use. 2064 * @syscap SystemCapability.Communication.NetStack 2065 * @crossplatform 2066 * @since 10 2067 */ 2068 /** 2069 * Reserved for future use. 2070 * @syscap SystemCapability.Communication.NetStack 2071 * @crossplatform 2072 * @atomicservice 2073 * @since 11 2074 */ 2075 PAYMENT_REQUIRED, 2076 2077 /** 2078 * The server understands the request from the requesting client, but refuses to execute it. 2079 * @syscap SystemCapability.Communication.NetStack 2080 * @since 6 2081 */ 2082 /** 2083 * The server understands the request from the requesting client, but refuses to execute it. 2084 * @syscap SystemCapability.Communication.NetStack 2085 * @crossplatform 2086 * @since 10 2087 */ 2088 /** 2089 * The server understands the request from the requesting client, but refuses to execute it. 2090 * @syscap SystemCapability.Communication.NetStack 2091 * @crossplatform 2092 * @atomicservice 2093 * @since 11 2094 */ 2095 FORBIDDEN, 2096 2097 /** 2098 * The server was unable to find resources (web pages) based on the client's request. 2099 * @syscap SystemCapability.Communication.NetStack 2100 * @since 6 2101 */ 2102 /** 2103 * The server was unable to find resources (web pages) based on the client's request. 2104 * @syscap SystemCapability.Communication.NetStack 2105 * @crossplatform 2106 * @since 10 2107 */ 2108 /** 2109 * The server was unable to find resources (web pages) based on the client's request. 2110 * @syscap SystemCapability.Communication.NetStack 2111 * @crossplatform 2112 * @atomicservice 2113 * @since 11 2114 */ 2115 NOT_FOUND, 2116 2117 /** 2118 * The method in the client request is prohibited. 2119 * @syscap SystemCapability.Communication.NetStack 2120 * @since 6 2121 */ 2122 /** 2123 * The method in the client request is prohibited. 2124 * @syscap SystemCapability.Communication.NetStack 2125 * @crossplatform 2126 * @since 10 2127 */ 2128 /** 2129 * The method in the client request is prohibited. 2130 * @syscap SystemCapability.Communication.NetStack 2131 * @crossplatform 2132 * @atomicservice 2133 * @since 11 2134 */ 2135 BAD_METHOD, 2136 2137 /** 2138 * The server is unable to complete the request based on the content characteristics requested by the client. 2139 * @syscap SystemCapability.Communication.NetStack 2140 * @since 6 2141 */ 2142 /** 2143 * The server is unable to complete the request based on the content characteristics requested by the client. 2144 * @syscap SystemCapability.Communication.NetStack 2145 * @crossplatform 2146 * @since 10 2147 */ 2148 /** 2149 * The server is unable to complete the request based on the content characteristics requested by the client. 2150 * @syscap SystemCapability.Communication.NetStack 2151 * @crossplatform 2152 * @atomicservice 2153 * @since 11 2154 */ 2155 NOT_ACCEPTABLE, 2156 2157 /** 2158 * Request authentication of the proxy's identity. 2159 * @syscap SystemCapability.Communication.NetStack 2160 * @since 6 2161 */ 2162 /** 2163 * Request authentication of the proxy's identity. 2164 * @syscap SystemCapability.Communication.NetStack 2165 * @crossplatform 2166 * @since 10 2167 */ 2168 /** 2169 * Request authentication of the proxy's identity. 2170 * @syscap SystemCapability.Communication.NetStack 2171 * @crossplatform 2172 * @atomicservice 2173 * @since 11 2174 */ 2175 PROXY_AUTH, 2176 2177 /** 2178 * The request took too long and timed out. 2179 * @syscap SystemCapability.Communication.NetStack 2180 * @since 6 2181 */ 2182 /** 2183 * The request took too long and timed out. 2184 * @syscap SystemCapability.Communication.NetStack 2185 * @crossplatform 2186 * @since 10 2187 */ 2188 /** 2189 * The request took too long and timed out. 2190 * @syscap SystemCapability.Communication.NetStack 2191 * @crossplatform 2192 * @atomicservice 2193 * @since 11 2194 */ 2195 CLIENT_TIMEOUT, 2196 2197 /** 2198 * <p>The server may have returned this code when completing the client's PUT request, 2199 * as there was a conflict when the server was processing the request.</p> 2200 * @syscap SystemCapability.Communication.NetStack 2201 * @since 6 2202 */ 2203 /** 2204 * <p>The server may have returned this code when completing the client's PUT request, 2205 * as there was a conflict when the server was processing the request.</p> 2206 * @syscap SystemCapability.Communication.NetStack 2207 * @crossplatform 2208 * @since 10 2209 */ 2210 /** 2211 * <p>The server may have returned this code when completing the client's PUT request, 2212 * as there was a conflict when the server was processing the request.</p> 2213 * @syscap SystemCapability.Communication.NetStack 2214 * @crossplatform 2215 * @atomicservice 2216 * @since 11 2217 */ 2218 CONFLICT, 2219 2220 /** 2221 * The resource requested by the client no longer exists. 2222 * @syscap SystemCapability.Communication.NetStack 2223 * @since 6 2224 */ 2225 /** 2226 * The resource requested by the client no longer exists. 2227 * @syscap SystemCapability.Communication.NetStack 2228 * @crossplatform 2229 * @since 10 2230 */ 2231 /** 2232 * The resource requested by the client no longer exists. 2233 * @syscap SystemCapability.Communication.NetStack 2234 * @crossplatform 2235 * @atomicservice 2236 * @since 11 2237 */ 2238 GONE, 2239 2240 /** 2241 * The server is unable to process request information sent by the client without Content Length. 2242 * @syscap SystemCapability.Communication.NetStack 2243 * @since 6 2244 */ 2245 /** 2246 * The server is unable to process request information sent by the client without Content Length. 2247 * @syscap SystemCapability.Communication.NetStack 2248 * @crossplatform 2249 * @since 10 2250 */ 2251 /** 2252 * The server is unable to process request information sent by the client without Content Length. 2253 * @syscap SystemCapability.Communication.NetStack 2254 * @crossplatform 2255 * @atomicservice 2256 * @since 11 2257 */ 2258 LENGTH_REQUIRED, 2259 2260 /** 2261 * The prerequisite for requesting information from the client is incorrect. 2262 * @syscap SystemCapability.Communication.NetStack 2263 * @since 6 2264 */ 2265 /** 2266 * The prerequisite for requesting information from the client is incorrect. 2267 * @syscap SystemCapability.Communication.NetStack 2268 * @crossplatform 2269 * @since 10 2270 */ 2271 /** 2272 * The prerequisite for requesting information from the client is incorrect. 2273 * @syscap SystemCapability.Communication.NetStack 2274 * @crossplatform 2275 * @atomicservice 2276 * @since 11 2277 */ 2278 PRECON_FAILED, 2279 2280 /** 2281 * The request was rejected because the requested entity was too large for the server to process. 2282 * @syscap SystemCapability.Communication.NetStack 2283 * @since 6 2284 */ 2285 /** 2286 * The request was rejected because the requested entity was too large for the server to process. 2287 * @syscap SystemCapability.Communication.NetStack 2288 * @crossplatform 2289 * @since 10 2290 */ 2291 /** 2292 * The request was rejected because the requested entity was too large for the server to process. 2293 * @syscap SystemCapability.Communication.NetStack 2294 * @crossplatform 2295 * @atomicservice 2296 * @since 11 2297 */ 2298 ENTITY_TOO_LARGE, 2299 2300 /** 2301 * The requested URI is too long (usually a URL) and the server cannot process it. 2302 * @syscap SystemCapability.Communication.NetStack 2303 * @since 6 2304 */ 2305 /** 2306 * The requested URI is too long (usually a URL) and the server cannot process it. 2307 * @syscap SystemCapability.Communication.NetStack 2308 * @crossplatform 2309 * @since 10 2310 */ 2311 /** 2312 * The requested URI is too long (usually a URL) and the server cannot process it. 2313 * @syscap SystemCapability.Communication.NetStack 2314 * @crossplatform 2315 * @atomicservice 2316 * @since 11 2317 */ 2318 REQ_TOO_LONG, 2319 2320 /** 2321 * The server is unable to process the requested format. 2322 * @syscap SystemCapability.Communication.NetStack 2323 * @since 6 2324 */ 2325 /** 2326 * The server is unable to process the requested format. 2327 * @syscap SystemCapability.Communication.NetStack 2328 * @crossplatform 2329 * @since 10 2330 */ 2331 /** 2332 * The server is unable to process the requested format. 2333 * @syscap SystemCapability.Communication.NetStack 2334 * @crossplatform 2335 * @atomicservice 2336 * @since 11 2337 */ 2338 UNSUPPORTED_TYPE, 2339 2340 /** 2341 * The server cannot process the requested data range. 2342 * @syscap SystemCapability.Communication.NetStack 2343 * @crossplatform 2344 * @atomicservice 2345 * @since 12 2346 */ 2347 RANGE_NOT_SATISFIABLE, 2348 2349 /** 2350 * Internal server error, unable to complete the request. 2351 * @syscap SystemCapability.Communication.NetStack 2352 * @since 6 2353 */ 2354 /** 2355 * Internal server error, unable to complete the request. 2356 * @syscap SystemCapability.Communication.NetStack 2357 * @crossplatform 2358 * @since 10 2359 */ 2360 /** 2361 * Internal server error, unable to complete the request. 2362 * @syscap SystemCapability.Communication.NetStack 2363 * @crossplatform 2364 * @atomicservice 2365 * @since 11 2366 */ 2367 INTERNAL_ERROR = 500, 2368 2369 /** 2370 * The server does not support the requested functionality and cannot complete the request. 2371 * @syscap SystemCapability.Communication.NetStack 2372 * @since 6 2373 */ 2374 /** 2375 * The server does not support the requested functionality and cannot complete the request. 2376 * @syscap SystemCapability.Communication.NetStack 2377 * @crossplatform 2378 * @since 10 2379 */ 2380 /** 2381 * The server does not support the requested functionality and cannot complete the request. 2382 * @syscap SystemCapability.Communication.NetStack 2383 * @crossplatform 2384 * @atomicservice 2385 * @since 11 2386 */ 2387 NOT_IMPLEMENTED, 2388 2389 /** 2390 * The server acting as a gateway or proxy received an invalid request from the remote server. 2391 * @syscap SystemCapability.Communication.NetStack 2392 * @since 6 2393 */ 2394 /** 2395 * The server acting as a gateway or proxy received an invalid request from the remote server. 2396 * @syscap SystemCapability.Communication.NetStack 2397 * @crossplatform 2398 * @since 10 2399 */ 2400 /** 2401 * The server acting as a gateway or proxy received an invalid request from the remote server. 2402 * @syscap SystemCapability.Communication.NetStack 2403 * @crossplatform 2404 * @atomicservice 2405 * @since 11 2406 */ 2407 BAD_GATEWAY, 2408 2409 /** 2410 * Due to overload or system maintenance, the server is temporarily unable to process client requests. 2411 * @syscap SystemCapability.Communication.NetStack 2412 * @since 6 2413 */ 2414 /** 2415 * Due to overload or system maintenance, the server is temporarily unable to process client requests. 2416 * @syscap SystemCapability.Communication.NetStack 2417 * @crossplatform 2418 * @since 10 2419 */ 2420 /** 2421 * Due to overload or system maintenance, the server is temporarily unable to process client requests. 2422 * @syscap SystemCapability.Communication.NetStack 2423 * @crossplatform 2424 * @atomicservice 2425 * @since 11 2426 */ 2427 UNAVAILABLE, 2428 2429 /** 2430 * The server acting as a gateway or proxy did not obtain requests from the remote server in a timely manner. 2431 * @syscap SystemCapability.Communication.NetStack 2432 * @since 6 2433 */ 2434 /** 2435 * The server acting as a gateway or proxy did not obtain requests from the remote server in a timely manner. 2436 * @syscap SystemCapability.Communication.NetStack 2437 * @crossplatform 2438 * @since 10 2439 */ 2440 /** 2441 * The server acting as a gateway or proxy did not obtain requests from the remote server in a timely manner. 2442 * @syscap SystemCapability.Communication.NetStack 2443 * @crossplatform 2444 * @atomicservice 2445 * @since 11 2446 */ 2447 GATEWAY_TIMEOUT, 2448 2449 /** 2450 * The version of the HTTP protocol requested by the server. 2451 * @syscap SystemCapability.Communication.NetStack 2452 * @since 6 2453 */ 2454 /** 2455 * The version of the HTTP protocol requested by the server. 2456 * @syscap SystemCapability.Communication.NetStack 2457 * @crossplatform 2458 * @since 10 2459 */ 2460 /** 2461 * The version of the HTTP protocol requested by the server. 2462 * @syscap SystemCapability.Communication.NetStack 2463 * @crossplatform 2464 * @atomicservice 2465 * @since 11 2466 */ 2467 VERSION 2468 } 2469 2470 /** 2471 * Supported protocols. 2472 * @enum {string} 2473 * @syscap SystemCapability.Communication.NetStack 2474 * @since 9 2475 */ 2476 /** 2477 * Supported protocols. 2478 * @enum {string} 2479 * @syscap SystemCapability.Communication.NetStack 2480 * @crossplatform 2481 * @since 10 2482 */ 2483 /** 2484 * Supported protocols. 2485 * @enum {string} 2486 * @syscap SystemCapability.Communication.NetStack 2487 * @crossplatform 2488 * @atomicservice 2489 * @since 11 2490 */ 2491 2492 export enum HttpProtocol { 2493 /** 2494 * Protocol http1.1 2495 * @syscap SystemCapability.Communication.NetStack 2496 * @since 9 2497 */ 2498 /** 2499 * Protocol http1.1 2500 * @syscap SystemCapability.Communication.NetStack 2501 * @crossplatform 2502 * @since 10 2503 */ 2504 /** 2505 * Protocol http1.1 2506 * @syscap SystemCapability.Communication.NetStack 2507 * @crossplatform 2508 * @atomicservice 2509 * @since 11 2510 */ 2511 HTTP1_1, 2512 2513 /** 2514 * Protocol http2 2515 * @syscap SystemCapability.Communication.NetStack 2516 * @since 9 2517 */ 2518 /** 2519 * Protocol http2 2520 * @syscap SystemCapability.Communication.NetStack 2521 * @crossplatform 2522 * @since 10 2523 */ 2524 /** 2525 * Protocol http2 2526 * @syscap SystemCapability.Communication.NetStack 2527 * @crossplatform 2528 * @atomicservice 2529 * @since 11 2530 */ 2531 HTTP2, 2532 2533 /** 2534 * Protocol http3 for https only. 2535 * Cause error if using http only or not supporting http3 on this device. 2536 * Fallback to http2 or http1.1 if needed. 2537 * @syscap SystemCapability.Communication.NetStack 2538 * @since 11 2539 */ 2540 /** 2541 * Protocol http3 for https only. 2542 * Cause error if using http only or not supporting http3 on this device. 2543 * Fallback to http2 or http1.1 if needed. 2544 * @syscap SystemCapability.Communication.NetStack 2545 * @crossplatform 2546 * @since 12 2547 */ 2548 HTTP3 2549 } 2550 2551 /** 2552 * Indicates the type of the returned data. 2553 * @enum {number} 2554 * @syscap SystemCapability.Communication.NetStack 2555 * @since 9 2556 */ 2557 /** 2558 * Indicates the type of the returned data. 2559 * @enum {number} 2560 * @syscap SystemCapability.Communication.NetStack 2561 * @crossplatform 2562 * @since 10 2563 */ 2564 /** 2565 * Indicates the type of the returned data. 2566 * @enum {number} 2567 * @syscap SystemCapability.Communication.NetStack 2568 * @crossplatform 2569 * @atomicservice 2570 * @since 11 2571 */ 2572 export enum HttpDataType { 2573 /** 2574 * The returned type is string. 2575 * @syscap SystemCapability.Communication.NetStack 2576 * @since 9 2577 */ 2578 /** 2579 * The returned type is string. 2580 * @syscap SystemCapability.Communication.NetStack 2581 * @crossplatform 2582 * @since 10 2583 */ 2584 /** 2585 * The returned type is string. 2586 * @syscap SystemCapability.Communication.NetStack 2587 * @crossplatform 2588 * @atomicservice 2589 * @since 11 2590 */ 2591 STRING, 2592 2593 /** 2594 * The returned type is Object. 2595 * @syscap SystemCapability.Communication.NetStack 2596 * @since 9 2597 */ 2598 /** 2599 * The returned type is Object. 2600 * @syscap SystemCapability.Communication.NetStack 2601 * @crossplatform 2602 * @since 10 2603 */ 2604 /** 2605 * The returned type is Object. 2606 * @syscap SystemCapability.Communication.NetStack 2607 * @crossplatform 2608 * @atomicservice 2609 * @since 11 2610 */ 2611 OBJECT = 1, 2612 2613 /** 2614 * The returned type is ArrayBuffer. 2615 * @syscap SystemCapability.Communication.NetStack 2616 * @since 9 2617 */ 2618 /** 2619 * The returned type is ArrayBuffer. 2620 * @syscap SystemCapability.Communication.NetStack 2621 * @crossplatform 2622 * @since 10 2623 */ 2624 /** 2625 * The returned type is ArrayBuffer. 2626 * @syscap SystemCapability.Communication.NetStack 2627 * @crossplatform 2628 * @atomicservice 2629 * @since 11 2630 */ 2631 ARRAY_BUFFER = 2 2632 } 2633 2634 /** 2635 * Defines the response to an HTTP request. 2636 * @interface HttpResponse 2637 * @syscap SystemCapability.Communication.NetStack 2638 * @since 6 2639 */ 2640 /** 2641 * Defines the response to an HTTP request. 2642 * @interface HttpResponse 2643 * @syscap SystemCapability.Communication.NetStack 2644 * @crossplatform 2645 * @since 10 2646 */ 2647 /** 2648 * Defines the response to an HTTP request. 2649 * @interface HttpResponse 2650 * @syscap SystemCapability.Communication.NetStack 2651 * @crossplatform 2652 * @atomicservice 2653 * @since 11 2654 */ 2655 export interface HttpResponse { 2656 /** 2657 * result can be a string (API 6) or an ArrayBuffer(API 8). Object is deprecated from API 8. 2658 * If {@link HttpRequestOptions#expectDataType} is set, the system preferentially returns this parameter. 2659 * @type {string | Object | ArrayBuffer} 2660 * @syscap SystemCapability.Communication.NetStack 2661 * @since 6 2662 */ 2663 /** 2664 * result can be a string (API 6) or an ArrayBuffer(API 8). Object is deprecated from API 8. 2665 * If {@link HttpRequestOptions#expectDataType} is set, the system preferentially returns this parameter. 2666 * @type {string | Object | ArrayBuffer} 2667 * @syscap SystemCapability.Communication.NetStack 2668 * @crossplatform 2669 * @since 10 2670 */ 2671 /** 2672 * result can be a string (API 6) or an ArrayBuffer(API 8). Object is deprecated from API 8. 2673 * If {@link HttpRequestOptions#expectDataType} is set, the system preferentially returns this parameter. 2674 * @type {string | Object | ArrayBuffer} 2675 * @syscap SystemCapability.Communication.NetStack 2676 * @crossplatform 2677 * @atomicservice 2678 * @since 11 2679 */ 2680 result: string | Object | ArrayBuffer; 2681 2682 /** 2683 * If the resultType is string, you can get result directly. 2684 * If the resultType is Object, you can get result such as this: result['key']. 2685 * If the resultType is ArrayBuffer, you can use ArrayBuffer to create the binary objects. 2686 * @type {HttpDataType} 2687 * @syscap SystemCapability.Communication.NetStack 2688 * @since 9 2689 */ 2690 /** 2691 * If the resultType is string, you can get result directly. 2692 * If the resultType is Object, you can get result such as this: result['key']. 2693 * If the resultType is ArrayBuffer, you can use ArrayBuffer to create the binary objects. 2694 * @type {HttpDataType} 2695 * @syscap SystemCapability.Communication.NetStack 2696 * @crossplatform 2697 * @since 10 2698 */ 2699 /** 2700 * If the resultType is string, you can get result directly. 2701 * If the resultType is Object, you can get result such as this: result['key']. 2702 * If the resultType is ArrayBuffer, you can use ArrayBuffer to create the binary objects. 2703 * @type {HttpDataType} 2704 * @syscap SystemCapability.Communication.NetStack 2705 * @crossplatform 2706 * @atomicservice 2707 * @since 11 2708 */ 2709 resultType: HttpDataType; 2710 2711 /** 2712 * Server status code. 2713 * @type {ResponseCode | number} 2714 * @syscap SystemCapability.Communication.NetStack 2715 * @since 6 2716 */ 2717 /** 2718 * Server status code. 2719 * @type {ResponseCode | number} 2720 * @syscap SystemCapability.Communication.NetStack 2721 * @crossplatform 2722 * @since 10 2723 */ 2724 /** 2725 * Server status code. 2726 * @type {ResponseCode | number} 2727 * @syscap SystemCapability.Communication.NetStack 2728 * @crossplatform 2729 * @atomicservice 2730 * @since 11 2731 */ 2732 responseCode: ResponseCode | number; 2733 2734 /** 2735 * All headers in the response from the server. 2736 * @type {Object} 2737 * @syscap SystemCapability.Communication.NetStack 2738 * @since 6 2739 */ 2740 /** 2741 * All headers in the response from the server. 2742 * @type {Object} 2743 * @syscap SystemCapability.Communication.NetStack 2744 * @crossplatform 2745 * @since 10 2746 */ 2747 /** 2748 * All headers in the response from the server. 2749 * @type {Object} 2750 * @syscap SystemCapability.Communication.NetStack 2751 * @crossplatform 2752 * @atomicservice 2753 * @since 11 2754 */ 2755 header: Object; 2756 2757 /** 2758 * Cookies returned by the server. 2759 * @type {string} 2760 * @syscap SystemCapability.Communication.NetStack 2761 * @since 8 2762 */ 2763 /** 2764 * Cookies returned by the server. 2765 * @type {string} 2766 * @syscap SystemCapability.Communication.NetStack 2767 * @crossplatform 2768 * @since 10 2769 */ 2770 /** 2771 * Cookies returned by the server. 2772 * @type {string} 2773 * @syscap SystemCapability.Communication.NetStack 2774 * @crossplatform 2775 * @atomicservice 2776 * @since 11 2777 */ 2778 cookies: string; 2779 2780 /** 2781 * The time taken of various stages of HTTP request. 2782 * @type {PerformanceTiming} 2783 * @syscap SystemCapability.Communication.NetStack 2784 * @since 11 2785 */ 2786 /** 2787 * The time taken of various stages of HTTP request. 2788 * @type {PerformanceTiming} 2789 * @syscap SystemCapability.Communication.NetStack 2790 * @crossplatform 2791 * @since 12 2792 */ 2793 performanceTiming: PerformanceTiming; 2794 } 2795 2796 /** 2797 * Counting the time taken of various stages of HTTP request. 2798 * @interface PerformanceTiming 2799 * @syscap SystemCapability.Communication.NetStack 2800 * @since 11 2801 */ 2802 /** 2803 * Counting the time taken of various stages of HTTP request. 2804 * @interface PerformanceTiming 2805 * @syscap SystemCapability.Communication.NetStack 2806 * @crossplatform 2807 * @since 12 2808 */ 2809 export interface PerformanceTiming { 2810 /** 2811 * Time taken from startup to DNS resolution completion, in milliseconds. 2812 * @type {number} 2813 * @syscap SystemCapability.Communication.NetStack 2814 * @since 11 2815 */ 2816 /** 2817 * Time taken from startup to DNS resolution completion, in milliseconds. 2818 * @type {number} 2819 * @syscap SystemCapability.Communication.NetStack 2820 * @crossplatform 2821 * @since 12 2822 */ 2823 dnsTiming: number; 2824 2825 /** 2826 * Time taken from startup to TCP connection completion, in milliseconds. 2827 * @type {number} 2828 * @syscap SystemCapability.Communication.NetStack 2829 * @since 11 2830 */ 2831 /** 2832 * Time taken from startup to TCP connection completion, in milliseconds. 2833 * @type {number} 2834 * @syscap SystemCapability.Communication.NetStack 2835 * @crossplatform 2836 * @since 12 2837 */ 2838 tcpTiming: number; 2839 2840 /** 2841 * Time taken from startup to TLS connection completion, in milliseconds. 2842 * @type {number} 2843 * @syscap SystemCapability.Communication.NetStack 2844 * @since 11 2845 */ 2846 /** 2847 * Time taken from startup to TLS connection completion, in milliseconds. 2848 * @type {number} 2849 * @syscap SystemCapability.Communication.NetStack 2850 * @crossplatform 2851 * @since 12 2852 */ 2853 tlsTiming: number; 2854 2855 /** 2856 * Time taken from startup to start sending the first byte, in milliseconds. 2857 * @type {number} 2858 * @syscap SystemCapability.Communication.NetStack 2859 * @since 11 2860 */ 2861 /** 2862 * Time taken from startup to start sending the first byte, in milliseconds. 2863 * @type {number} 2864 * @syscap SystemCapability.Communication.NetStack 2865 * @crossplatform 2866 * @since 12 2867 */ 2868 firstSendTiming: number; 2869 2870 /** 2871 * Time taken from startup to receiving the first byte, in milliseconds. 2872 * @type {number} 2873 * @syscap SystemCapability.Communication.NetStack 2874 * @since 11 2875 */ 2876 /** 2877 * Time taken from startup to receiving the first byte, in milliseconds. 2878 * @type {number} 2879 * @syscap SystemCapability.Communication.NetStack 2880 * @crossplatform 2881 * @since 12 2882 */ 2883 firstReceiveTiming: number; 2884 2885 /** 2886 * Time taken from startup to the completion of the request, in milliseconds. 2887 * @type {number} 2888 * @syscap SystemCapability.Communication.NetStack 2889 * @since 11 2890 */ 2891 /** 2892 * Time taken from startup to the completion of the request, in milliseconds. 2893 * @type {number} 2894 * @syscap SystemCapability.Communication.NetStack 2895 * @crossplatform 2896 * @since 12 2897 */ 2898 totalFinishTiming: number; 2899 2900 /** 2901 * Time taken from startup to completion of all redirection steps, in milliseconds. 2902 * @type {number} 2903 * @syscap SystemCapability.Communication.NetStack 2904 * @since 11 2905 */ 2906 /** 2907 * Time taken from startup to completion of all redirection steps, in milliseconds. 2908 * @type {number} 2909 * @syscap SystemCapability.Communication.NetStack 2910 * @crossplatform 2911 * @since 12 2912 */ 2913 redirectTiming: number; 2914 2915 /** 2916 * Time taken from HTTP request to header completion, in milliseconds. 2917 * @type {number} 2918 * @syscap SystemCapability.Communication.NetStack 2919 * @since 11 2920 */ 2921 /** 2922 * Time taken from HTTP request to header completion, in milliseconds. 2923 * @type {number} 2924 * @syscap SystemCapability.Communication.NetStack 2925 * @crossplatform 2926 * @since 12 2927 */ 2928 responseHeaderTiming: number; 2929 2930 /** 2931 * Time taken from HTTP Request to body completion, in milliseconds. 2932 * @type {number} 2933 * @syscap SystemCapability.Communication.NetStack 2934 * @since 11 2935 */ 2936 /** 2937 * Time taken from HTTP Request to body completion, in milliseconds. 2938 * @type {number} 2939 * @syscap SystemCapability.Communication.NetStack 2940 * @crossplatform 2941 * @since 12 2942 */ 2943 responseBodyTiming: number; 2944 2945 /** 2946 * Time taken from HTTP Request to callback to the application, in milliseconds. 2947 * @type {number} 2948 * @syscap SystemCapability.Communication.NetStack 2949 * @since 11 2950 */ 2951 /** 2952 * Time taken from HTTP Request to callback to the application, in milliseconds. 2953 * @type {number} 2954 * @syscap SystemCapability.Communication.NetStack 2955 * @crossplatform 2956 * @since 12 2957 */ 2958 totalTiming: number; 2959 } 2960 2961 /** 2962 * This interface is used to obtain the progress information of file upload or download. 2963 * @interface DataReceiveProgressInfo 2964 * @syscap SystemCapability.Communication.NetStack 2965 * @since 11 2966 */ 2967 /** 2968 * This interface is used to obtain the progress information of file upload or download. 2969 * @interface DataReceiveProgressInfo 2970 * @syscap SystemCapability.Communication.NetStack 2971 * @crossplatform 2972 * @since 12 2973 */ 2974 export interface DataReceiveProgressInfo { 2975 /** 2976 * Number of data bytes received. 2977 * @type { number } 2978 * @syscap SystemCapability.Communication.NetStack 2979 * @since 11 2980 */ 2981 /** 2982 * Number of data bytes received. 2983 * @type { number } 2984 * @syscap SystemCapability.Communication.NetStack 2985 * @crossplatform 2986 * @since 12 2987 */ 2988 receiveSize: number; 2989 /** 2990 * Total number of bytes to receive. 2991 * @type { number } 2992 * @syscap SystemCapability.Communication.NetStack 2993 * @since 11 2994 */ 2995 /** 2996 * Total number of bytes to receive. 2997 * @type { number } 2998 * @syscap SystemCapability.Communication.NetStack 2999 * @crossplatform 3000 * @since 12 3001 */ 3002 totalSize: number; 3003 } 3004 3005 /** 3006 * This interface is used to monitor the progress of sending data. 3007 * @interface DataSendProgressInfo 3008 * @syscap SystemCapability.Communication.NetStack 3009 * @since 11 3010 */ 3011 /** 3012 * This interface is used to monitor the progress of sending data. 3013 * @interface DataSendProgressInfo 3014 * @syscap SystemCapability.Communication.NetStack 3015 * @crossplatform 3016 * @since 12 3017 */ 3018 export interface DataSendProgressInfo { 3019 /** 3020 * Used to specify the data size to be sent. 3021 * @type { number } 3022 * @syscap SystemCapability.Communication.NetStack 3023 * @since 11 3024 */ 3025 /** 3026 * Used to specify the data size to be sent. 3027 * @type { number } 3028 * @syscap SystemCapability.Communication.NetStack 3029 * @crossplatform 3030 * @since 12 3031 */ 3032 sendSize: number; 3033 /** 3034 * Total number of bytes to receive. 3035 * @type { number } 3036 * @syscap SystemCapability.Communication.NetStack 3037 * @since 11 3038 */ 3039 /** 3040 * Total number of bytes to receive. 3041 * @type { number } 3042 * @syscap SystemCapability.Communication.NetStack 3043 * @crossplatform 3044 * @since 12 3045 */ 3046 totalSize: number; 3047 } 3048 3049 /** 3050 * Creates a default {@code HttpResponseCache} object to store the responses of HTTP access requests. 3051 * @param { number } cacheSize - the size of cache(max value is 10MB), default is 10*1024*1024(10MB). 3052 * @returns { HttpResponseCache } the HttpResponseCache of the createHttpResponseCache. 3053 * @syscap SystemCapability.Communication.NetStack 3054 * @since 9 3055 */ 3056 /** 3057 * Creates a default {@code HttpResponseCache} object to store the responses of HTTP access requests. 3058 * @param { number } cacheSize - the size of cache(max value is 10MB), default is 10*1024*1024(10MB). 3059 * @returns { HttpResponseCache } the HttpResponseCache of the createHttpResponseCache. 3060 * @syscap SystemCapability.Communication.NetStack 3061 * @crossplatform 3062 * @since 10 3063 */ 3064 /** 3065 * Creates a default {@code HttpResponseCache} object to store the responses of HTTP access requests. 3066 * @param { number } cacheSize - the size of cache(max value is 10MB), default is 10*1024*1024(10MB). 3067 * @returns { HttpResponseCache } the HttpResponseCache of the createHttpResponseCache. 3068 * @syscap SystemCapability.Communication.NetStack 3069 * @crossplatform 3070 * @atomicservice 3071 * @since 11 3072 */ 3073 function createHttpResponseCache(cacheSize?: number): HttpResponseCache; 3074 3075 /** 3076 * Defines an object that stores the response to an HTTP request. 3077 * @interface HttpResponseCache 3078 * @syscap SystemCapability.Communication.NetStack 3079 * @since 9 3080 */ 3081 /** 3082 * Defines an object that stores the response to an HTTP request. 3083 * @interface HttpResponseCache 3084 * @syscap SystemCapability.Communication.NetStack 3085 * @crossplatform 3086 * @since 10 3087 */ 3088 /** 3089 * Defines an object that stores the response to an HTTP request. 3090 * @interface HttpResponseCache 3091 * @syscap SystemCapability.Communication.NetStack 3092 * @crossplatform 3093 * @atomicservice 3094 * @since 11 3095 */ 3096 export interface HttpResponseCache { 3097 /** 3098 * Writes data in the cache to the file system so that all the cached data can be accessed in the next HTTP request. 3099 * @param { AsyncCallback<void> } callback - the callback of flush. 3100 * @syscap SystemCapability.Communication.NetStack 3101 * @since 9 3102 */ 3103 /** 3104 * Writes data in the cache to the file system so that all the cached data can be accessed in the next HTTP request. 3105 * @param { AsyncCallback<void> } callback - the callback of flush. 3106 * @syscap SystemCapability.Communication.NetStack 3107 * @crossplatform 3108 * @since 10 3109 */ 3110 /** 3111 * Writes data in the cache to the file system so that all the cached data can be accessed in the next HTTP request. 3112 * @param { AsyncCallback<void> } callback - the callback of flush. 3113 * @syscap SystemCapability.Communication.NetStack 3114 * @crossplatform 3115 * @atomicservice 3116 * @since 11 3117 */ 3118 flush(callback: AsyncCallback<void>): void; 3119 3120 /** 3121 * Writes data in the cache to the file system so that all the cached data can be accessed in the next HTTP request. 3122 * @returns { Promise<void> } The promise returned by the flush. 3123 * @syscap SystemCapability.Communication.NetStack 3124 * @since 9 3125 */ 3126 /** 3127 * Writes data in the cache to the file system so that all the cached data can be accessed in the next HTTP request. 3128 * @returns { Promise<void> } The promise returned by the flush. 3129 * @syscap SystemCapability.Communication.NetStack 3130 * @crossplatform 3131 * @since 10 3132 */ 3133 /** 3134 * Writes data in the cache to the file system so that all the cached data can be accessed in the next HTTP request. 3135 * @returns { Promise<void> } The promise returned by the flush. 3136 * @syscap SystemCapability.Communication.NetStack 3137 * @crossplatform 3138 * @atomicservice 3139 * @since 11 3140 */ 3141 flush(): Promise<void>; 3142 3143 /** 3144 * Disables a cache and deletes the data in it. 3145 * @param { AsyncCallback<void> } callback - the callback of delete. 3146 * @syscap SystemCapability.Communication.NetStack 3147 * @since 9 3148 */ 3149 /** 3150 * Disables a cache and deletes the data in it. 3151 * @param { AsyncCallback<void> } callback - the callback of delete. 3152 * @syscap SystemCapability.Communication.NetStack 3153 * @crossplatform 3154 * @since 10 3155 */ 3156 /** 3157 * Disables a cache and deletes the data in it. 3158 * @param { AsyncCallback<void> } callback - the callback of delete. 3159 * @syscap SystemCapability.Communication.NetStack 3160 * @crossplatform 3161 * @atomicservice 3162 * @since 11 3163 */ 3164 delete(callback: AsyncCallback<void>): void; 3165 3166 /** 3167 * Disables a cache and deletes the data in it. 3168 * @returns { Promise<void> } The promise returned by the delete. 3169 * @syscap SystemCapability.Communication.NetStack 3170 * @since 9 3171 */ 3172 /** 3173 * Disables a cache and deletes the data in it. 3174 * @returns { Promise<void> } The promise returned by the delete. 3175 * @syscap SystemCapability.Communication.NetStack 3176 * @crossplatform 3177 * @since 10 3178 */ 3179 /** 3180 * Disables a cache and deletes the data in it. 3181 * @returns { Promise<void> } The promise returned by the delete. 3182 * @syscap SystemCapability.Communication.NetStack 3183 * @crossplatform 3184 * @atomicservice 3185 * @since 11 3186 */ 3187 delete(): Promise<void>; 3188 } 3189} 3190 3191export default http; 3192