diff --git a/zh-cn/application-dev/reference/apis/js-apis-http.md b/zh-cn/application-dev/reference/apis/js-apis-http.md index 879a70e6a09dcef744013644d58f63ed5f83846f..119bbce3f876e63af80bc0d5091af0e3708966ea 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-http.md +++ b/zh-cn/application-dev/reference/apis/js-apis-http.md @@ -98,7 +98,7 @@ createHttp(): HttpRequest | 类型 | 说明 | | :---------- | :----------------------------------------------------------- | -| HttpRequest | 返回一个HttpRequest对象,里面包括request、requestInStream、destroy、on和off方法。 | +| HttpRequest | 返回一个HttpRequest对象,里面包括request、destroy、on和off方法。 | **示例:** @@ -400,251 +400,6 @@ let httpRequest = http.createHttp(); httpRequest.destroy(); ``` -### requestInStream10+ - -requestInStream(url: string, callback: AsyncCallback\): void - -根据URL地址,发起HTTP网络请求并返回流式响应,使用callback方式作为异步方法。 - -**需要权限**:ohos.permission.INTERNET - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ---------------------------------------------- | ---- | ----------------------------------------------- | -| url | string | 是 | 发起网络请求的URL地址。 | -| callback | AsyncCallback\<[number](#responsecode)\> | 是 | 回调函数。 | - -**错误码:** - -| 错误码ID | 错误信息 | -|---------|-------------------------------------------------------| -| 401 | Parameter error. | -| 201 | Permission denied. | -| 2300001 | Unsupported protocol. | -| 2300003 | URL using bad/illegal format or missing URL. | -| 2300005 | Couldn't resolve proxy name. | -| 2300006 | Couldn't resolve host name. | -| 2300007 | Couldn't connect to server. | -| 2300008 | Weird server reply. | -| 2300009 | Access denied to remote resource. | -| 2300016 | Error in the HTTP2 framing layer. | -| 2300018 | Transferred a partial file. | -| 2300023 | Failed writing received data to disk/application. | -| 2300025 | Upload failed. | -| 2300026 | Failed to open/read local data from file/application. | -| 2300027 | Out of memory. | -| 2300028 | Timeout was reached. | -| 2300047 | Number of redirects hit maximum amount. | -| 2300052 | Server returned nothing (no headers, no data). | -| 2300055 | Failed sending data to the peer. | -| 2300056 | Failure when receiving data from the peer. | -| 2300058 | Problem with the local SSL certificate. | -| 2300059 | Couldn't use specified SSL cipher. | -| 2300060 | SSL peer certificate or SSH remote key was not OK. | -| 2300061 | Unrecognized or bad HTTP Content or Transfer-Encoding.| -| 2300063 | Maximum file size exceeded. | -| 2300070 | Disk full or allocation exceeded. | -| 2300073 | Remote file already exists. | -| 2300077 | Problem with the SSL CA cert (path? access rights?). | -| 2300078 | Remote file not found. | -| 2300094 | An authentication function returned an error. | -| 2300999 | Unknown Other Error. | - -> **错误码说明:** -> 以上错误码的详细介绍参见[HTTP错误码](../errorcodes/errorcode-net-http.md)。 -> HTTP 错误码映射关系:2300000 + curl错误码。更多常用错误码,可参考curl错误码:https://curl.se/libcurl/c/libcurl-errors.html - -**示例:** - -```ts -import http from '@ohos.net.http'; -import { BusinessError } from '@ohos.base'; - -let httpRequest = http.createHttp(); -httpRequest.requestInStream("EXAMPLE_URL", (err: BusinessError, data: number) => { - if (!err) { - console.info("requestInStream OK! ResponseCode is " + JSON.stringify(data)); - } else { - console.info("requestInStream ERROR : err = " + JSON.stringify(err)); - } -}) -``` - -### requestInStream10+ - -requestInStream(url: string, options: HttpRequestOptions, callback: AsyncCallback\): void - -根据URL地址和相关配置项,发起HTTP网络请求并返回流式响应,使用callback方式作为异步方法。 - -**需要权限**:ohos.permission.INTERNET - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ---------------------------------------------- | ---- | ----------------------------------------------- | -| url | string | 是 | 发起网络请求的URL地址。 | -| options | HttpRequestOptions | 是 | 参考[HttpRequestOptions](#httprequestoptions)。 | -| callback | AsyncCallback\<[number](#responsecode)\> | 是 | 回调函数。 | - -**错误码:** - -| 错误码ID | 错误信息 | -|---------|-------------------------------------------------------| -| 401 | Parameter error. | -| 201 | Permission denied. | -| 2300001 | Unsupported protocol. | -| 2300003 | URL using bad/illegal format or missing URL. | -| 2300005 | Couldn't resolve proxy name. | -| 2300006 | Couldn't resolve host name. | -| 2300007 | Couldn't connect to server. | -| 2300008 | Weird server reply. | -| 2300009 | Access denied to remote resource. | -| 2300016 | Error in the HTTP2 framing layer. | -| 2300018 | Transferred a partial file. | -| 2300023 | Failed writing received data to disk/application. | -| 2300025 | Upload failed. | -| 2300026 | Failed to open/read local data from file/application. | -| 2300027 | Out of memory. | -| 2300028 | Timeout was reached. | -| 2300047 | Number of redirects hit maximum amount. | -| 2300052 | Server returned nothing (no headers, no data). | -| 2300055 | Failed sending data to the peer. | -| 2300056 | Failure when receiving data from the peer. | -| 2300058 | Problem with the local SSL certificate. | -| 2300059 | Couldn't use specified SSL cipher. | -| 2300060 | SSL peer certificate or SSH remote key was not OK. | -| 2300061 | Unrecognized or bad HTTP Content or Transfer-Encoding.| -| 2300063 | Maximum file size exceeded. | -| 2300070 | Disk full or allocation exceeded. | -| 2300073 | Remote file already exists. | -| 2300077 | Problem with the SSL CA cert (path? access rights?). | -| 2300078 | Remote file not found. | -| 2300094 | An authentication function returned an error. | -| 2300999 | Unknown Other Error. | - -> **错误码说明:** -> 以上错误码的详细介绍参见[HTTP错误码](../errorcodes/errorcode-net-http.md)。 -> HTTP 错误码映射关系:2300000 + curl错误码。更多常用错误码,可参考curl错误码:https://curl.se/libcurl/c/libcurl-errors.html - -**示例:** - -```ts -import http from '@ohos.net.http'; -import { BusinessError } from '@ohos.base'; - -class Header { - public contentType: string; - - constructor(contentType: string) { - this.contentType = contentType; - } -} - -let httpRequest = http.createHttp(); -httpRequest.requestInStream("EXAMPLE_URL", (err: BusinessError , data: number) => { - if (!err) { - console.info("requestInStream OK! ResponseCode is " + JSON.stringify(data)); - } else { - console.info("requestInStream ERROR : err = " + JSON.stringify(err)); - } -}) -``` - -### requestInStream10+ - -requestInStream(url: string, options? : HttpRequestOptions): Promise\ - -根据URL地址,发起HTTP网络请求并返回流式响应,使用Promise方式作为异步方法。 - -**需要权限**:ohos.permission.INTERNET - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------ | ---- | ----------------------------------------------- | -| url | string | 是 | 发起网络请求的URL地址。 | -| options | HttpRequestOptions | 否 | 参考[HttpRequestOptions](#httprequestoptions)。 | - -**返回值:** - -| 类型 | 说明 | -| :------------------------------------- | :-------------------------------- | -| Promise\<[number](#responsecode)\> | 以Promise形式返回发起请求的结果。 | - -**错误码:** - -| 错误码ID | 错误信息 | -|---------|-------------------------------------------------------| -| 401 | Parameter error. | -| 201 | Permission denied. | -| 2300001 | Unsupported protocol. | -| 2300003 | URL using bad/illegal format or missing URL. | -| 2300005 | Couldn't resolve proxy name. | -| 2300006 | Couldn't resolve host name. | -| 2300007 | Couldn't connect to server. | -| 2300008 | Weird server reply. | -| 2300009 | Access denied to remote resource. | -| 2300016 | Error in the HTTP2 framing layer. | -| 2300018 | Transferred a partial file. | -| 2300023 | Failed writing received data to disk/application. | -| 2300025 | Upload failed. | -| 2300026 | Failed to open/read local data from file/application. | -| 2300027 | Out of memory. | -| 2300028 | Timeout was reached. | -| 2300047 | Number of redirects hit maximum amount. | -| 2300052 | Server returned nothing (no headers, no data). | -| 2300055 | Failed sending data to the peer. | -| 2300056 | Failure when receiving data from the peer. | -| 2300058 | Problem with the local SSL certificate. | -| 2300059 | Couldn't use specified SSL cipher. | -| 2300060 | SSL peer certificate or SSH remote key was not OK. | -| 2300061 | Unrecognized or bad HTTP Content or Transfer-Encoding.| -| 2300063 | Maximum file size exceeded. | -| 2300070 | Disk full or allocation exceeded. | -| 2300073 | Remote file already exists. | -| 2300077 | Problem with the SSL CA cert (path? access rights?). | -| 2300078 | Remote file not found. | -| 2300094 | An authentication function returned an error. | -| 2300999 | Unknown Other Error. | - -> **错误码说明:** -> 以上错误码的详细介绍参见[HTTP错误码](../errorcodes/errorcode-net-http.md)。 -> HTTP 错误码映射关系:2300000 + curl错误码。更多常用错误码,可参考: - -**示例:** - -```ts -import http from '@ohos.net.http'; - -class Header { - public contentType: string; - - constructor(contentType: string) { - this.contentType = contentType; - } -} - -let httpRequest = http.createHttp(); -let promise = httpRequest.request("EXAMPLE_URL", { - method: http.RequestMethod.GET, - connectTimeout: 60000, - readTimeout: 60000, - header: new Header('application/json') -}); -promise.then((data: http.HttpResponse) => { - console.info("requestInStream OK!" + JSON.stringify(data)); -}).catch((err: Error) => { - console.info("requestInStream ERROR : err = " + JSON.stringify(err)); -}); -``` - ### on('headerReceive')(deprecated) on(type: 'headerReceive', callback: AsyncCallback\): void