Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
dbdfb789
D
Docs
项目概览
OpenHarmony
/
Docs
接近 2 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
dbdfb789
编写于
3月 28, 2023
作者:
O
openharmony_ci
提交者:
Gitee
3月 28, 2023
浏览文件
操作
浏览文件
下载
差异文件
!16590 [3.2 release] delete api10 for 3.2
Merge pull request !16590 from liyufan/OpenHarmony-3.2-Release
上级
4ff75af1
2f82673b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
1 addition
and
524 deletion
+1
-524
zh-cn/application-dev/connectivity/http-request.md
zh-cn/application-dev/connectivity/http-request.md
+0
-8
zh-cn/application-dev/reference/apis/js-apis-http.md
zh-cn/application-dev/reference/apis/js-apis-http.md
+1
-343
zh-cn/application-dev/reference/apis/js-apis-net-connection.md
.../application-dev/reference/apis/js-apis-net-connection.md
+0
-173
未找到文件。
zh-cn/application-dev/connectivity/http-request.md
浏览文件 @
dbdfb789
...
@@ -18,17 +18,10 @@ HTTP数据请求功能主要由http模块提供。
...
@@ -18,17 +18,10 @@ HTTP数据请求功能主要由http模块提供。
| ----------------------------------------- | ----------------------------------- |
| ----------------------------------------- | ----------------------------------- |
| createHttp() | 创建一个http请求。 |
| createHttp() | 创建一个http请求。 |
| request() | 根据URL地址,发起HTTP网络请求。 |
| request() | 根据URL地址,发起HTTP网络请求。 |
| request2()
<sup>
10+
</sup>
| 根据URL地址,发起HTTP网络请求并返回流式响应|
| destroy() | 中断请求任务。 |
| destroy() | 中断请求任务。 |
| on(type: 'headersReceive') | 订阅HTTP Response Header 事件。 |
| on(type: 'headersReceive') | 订阅HTTP Response Header 事件。 |
| off(type: 'headersReceive') | 取消订阅HTTP Response Header 事件。 |
| off(type: 'headersReceive') | 取消订阅HTTP Response Header 事件。 |
| once
\(
'headersReceive'
\)
<sup>
8+
</sup>
| 订阅HTTP Response Header 事件,但是只触发一次。|
| once
\(
'headersReceive'
\)
<sup>
8+
</sup>
| 订阅HTTP Response Header 事件,但是只触发一次。|
| on
\(
'dataReceive'
\)
<sup>
10+
</sup>
| 订阅HTTP流式响应数据接收事件。 |
| off
\(
'dataReceive'
\)
<sup>
10+
</sup>
| 取消订阅HTTP流式响应数据接收事件。 |
| on
\(
'dataEnd'
\)
<sup>
10+
</sup>
| 订阅HTTP流式响应数据接收完毕事件。 |
| off
\(
'dataEnd'
\)
<sup>
10+
</sup>
| 取消订阅HTTP流式响应数据接收完毕事件。 |
| on
\(
'dataProgress'
\)
<sup>
10+
</sup>
| 订阅HTTP流式响应数据接收进度事件。 |
| off
\(
'dataProgress'
\)
<sup>
10+
</sup>
| 取消订阅HTTP流式响应数据接收进度事件。 |
## request接口开发步骤
## request接口开发步骤
...
@@ -70,7 +63,6 @@ httpRequest.request(
...
@@ -70,7 +63,6 @@ httpRequest.request(
connectTimeout
:
60000
,
// 可选,默认为60000ms
connectTimeout
:
60000
,
// 可选,默认为60000ms
readTimeout
:
60000
,
// 可选,默认为60000ms
readTimeout
:
60000
,
// 可选,默认为60000ms
usingProtocol
:
http
.
HttpProtocol
.
HTTP1_1
,
// 可选,协议类型默认值由系统自动指定
usingProtocol
:
http
.
HttpProtocol
.
HTTP1_1
,
// 可选,协议类型默认值由系统自动指定
usingProxy
:
false
,
//可选,默认不使用网络代理,自API 10开始支持该属性
},
(
err
,
data
)
=>
{
},
(
err
,
data
)
=>
{
if
(
!
err
)
{
if
(
!
err
)
{
// data.result为HTTP响应内容,可根据业务需要进行解析
// data.result为HTTP响应内容,可根据业务需要进行解析
...
...
zh-cn/application-dev/reference/apis/js-apis-http.md
浏览文件 @
dbdfb789
...
@@ -45,7 +45,6 @@ httpRequest.request(
...
@@ -45,7 +45,6 @@ httpRequest.request(
connectTimeout
:
60000
,
// 可选,默认为60000ms
connectTimeout
:
60000
,
// 可选,默认为60000ms
readTimeout
:
60000
,
// 可选,默认为60000ms
readTimeout
:
60000
,
// 可选,默认为60000ms
usingProtocol
:
http
.
HttpProtocol
.
HTTP1_1
,
// 可选,协议类型默认值由系统自动指定
usingProtocol
:
http
.
HttpProtocol
.
HTTP1_1
,
// 可选,协议类型默认值由系统自动指定
usingProxy
:
false
,
//可选,默认不使用网络代理,自API 10开始支持该属性
},
(
err
,
data
)
=>
{
},
(
err
,
data
)
=>
{
if
(
!
err
)
{
if
(
!
err
)
{
// data.result为HTTP响应内容,可根据业务需要进行解析
// data.result为HTTP响应内容,可根据业务需要进行解析
...
@@ -77,7 +76,7 @@ createHttp(): HttpRequest
...
@@ -77,7 +76,7 @@ createHttp(): HttpRequest
| 类型 | 说明 |
| 类型 | 说明 |
| :---------- | :----------------------------------------------------------- |
| :---------- | :----------------------------------------------------------- |
| HttpRequest | 返回一个HttpRequest对象,里面包括request、
request2、
destroy、on和off方法。 |
| HttpRequest | 返回一个HttpRequest对象,里面包括request、destroy、on和off方法。 |
**示例:**
**示例:**
...
@@ -330,207 +329,6 @@ destroy(): void
...
@@ -330,207 +329,6 @@ destroy(): void
httpRequest
.
destroy
();
httpRequest
.
destroy
();
```
```
### request2<sup>10+</sup>
request2(url: string, callback: AsyncCallback
\<
void
\>
): void
根据URL地址和相关配置项,发起HTTP网络请求并返回流式响应,使用callback方式作为异步方法。
**需要权限**
:ohos.permission.INTERNET
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------- | ---- | ----------------------------------------------- |
| url | string | 是 | 发起网络请求的URL地址。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
|---------|-------------------------------------------------------|
| 401 | Parameter error. |
| 201 | Permission denied. |
| 2300003 | URL using bad/illegal format or missing URL. |
| 2300007 | Couldn't connect to server. |
| 2300028 | Timeout was reached. |
| 2300052 | Server returned nothing (no headers, no data). |
| 2300999 | Unknown Other Error. |
>**错误码说明:**
> 以上错误码的详细介绍参见[HTTP错误码](../errorcodes/errorcode-net-http.md)。
> HTTP 错误码映射关系:2300000 + curl错误码。更多常用错误码,可参考:[curl错误码](https://curl.se/libcurl/c/libcurl-errors.html)
**示例:**
```
js
httpRequest
.
request2
(
"
EXAMPLE_URL
"
,
(
err
)
=>
{
if
(
!
err
)
{
console
.
info
(
"
request2 OK!
"
);
}
else
{
console
.
info
(
"
request2 ERROR : err =
"
+
JSON
.
stringify
(
err
));
}
})
```
### request2<sup>10+</sup>
request2(url: string, options: HttpRequestOptions, callback: AsyncCallback
\<
void
\>
): void
根据URL地址和相关配置项,发起HTTP网络请求并返回流式响应,使用callback方式作为异步方法。
**需要权限**
:ohos.permission.INTERNET
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------- | ---- | ----------------------------------------------- |
| url | string | 是 | 发起网络请求的URL地址。 |
| options | HttpRequestOptions | 是 | 参考
[
HttpRequestOptions
](
#httprequestoptions
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 回调函数。 |
**错误码:**
| 错误码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)
**示例:**
```
js
httpRequest
.
request2
(
"
EXAMPLE_URL
"
,
{
method
:
http
.
RequestMethod
.
GET
,
header
:
{
'
Content-Type
'
:
'
application/json
'
},
readTimeout
:
60000
,
connectTimeout
:
60000
},
(
err
)
=>
{
if
(
!
err
)
{
console
.
info
(
"
request2 OK!
"
);
}
else
{
console
.
info
(
"
request2 ERROR : err =
"
+
JSON
.
stringify
(
err
));
}
})
```
### request2<sup>10+</sup>
request2(url: string, options? : HttpRequestOptions): Promise
\<
void
\>
根据URL地址,发起HTTP网络请求并返回流式响应,使用Promise方式作为异步方法。
**需要权限**
:ohos.permission.INTERNET
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------------------ | ---- | ----------------------------------------------- |
| url | string | 是 | 发起网络请求的URL地址。 |
| options | HttpRequestOptions | 否 | 参考
[
HttpRequestOptions
](
#httprequestoptions
)
。 |
**返回值:**
| 类型 | 说明 |
| :------------------------------------- | :-------------------------------- |
| Promise
\<
void
\>
| 以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错误码。更多常用错误码,可参考:
**示例:**
```
js
let
promise
=
httpRequest
.
request
(
"
EXAMPLE_URL
"
,
{
method
:
http
.
RequestMethod
.
GET
,
connectTimeout
:
60000
,
readTimeout
:
60000
,
header
:
{
'
Content-Type
'
:
'
application/json
'
}
});
promise
.
then
(()
=>
{
console
.
info
(
"
request2 OK!
"
);
}).
catch
((
err
)
=>
{
console
.
info
(
"
request2 ERROR : err =
"
+
JSON
.
stringify
(
err
));
});
```
```
### on('headerReceive')
### on('headerReceive')
...
@@ -655,146 +453,7 @@ httpRequest.once('headersReceive', (header) => {
...
@@ -655,146 +453,7 @@ httpRequest.once('headersReceive', (header) => {
console.info('header: ' + JSON.stringify(header));
console.info('header: ' + JSON.stringify(header));
});
});
```
```
### on('dataReceive')<sup>10+</sup>
on(type: 'dataReceive', callback: Callback
\<
ArrayBuffer
\>
): void
订阅HTTP流式响应数据接收事件。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | --------------------------------- |
| type | string | 是 | 订阅的事件类型,'dataReceive'。 |
| callback | AsyncCallback
\<
ArrayBuffer
\>
| 是 | 回调函数。 |
**示例:**
```
js
httpRequest
.
on
(
'
dataReceive
'
,
(
data
)
=>
{
console
.
info
(
'
dataReceive length:
'
+
JSON
.
stringify
(
data
.
byteLength
));
});
```
### off('dataReceive')<sup>10+</sup>
off(type: 'dataReceive', callback?: Callback
\<
ArrayBuffer
\>
): void
取消订阅HTTP流式响应数据接收事件。
>**说明:**
>可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------ | ---- | -------------------------------------- |
| type | string | 是 | 取消订阅的事件类型:'dataReceive'。 |
| callback | Callback
\<
ArrayBuffer
\>
| 否 | 回调函数。 |
**示例:**
```
js
httpRequest
.
off
(
'
dataReceive
'
);
```
### on('dataEnd')<sup>10+</sup>
on(type: 'dataEnd', callback: Callback
\<
void
\>
): void
订阅HTTP流式响应数据接收完毕事件。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | --------------------------------- |
| type | string | 是 | 订阅的事件类型,'dataEnd'。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 回调函数。 |
**示例:**
```
js
httpRequest
.
on
(
'
dataReceive
'
,
()
=>
{
console
.
info
(
'
Receive dataEnd!
'
);
});
```
### off('dataEnd')<sup>10+</sup>
off(type: 'dataEnd', callback?: Callback
\<
void
\>
): void
取消订阅HTTP流式响应数据接收完毕事件。
>**说明:**
>可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------ | ---- | -------------------------------------- |
| type | string | 是 | 取消订阅的事件类型:'dataEnd'。 |
| callback | Callback
\<
void
\>
| 否 | 回调函数。 |
**示例:**
```
js
httpRequest
.
off
(
'
dataEnd
'
);
```
### on('dataProgress')<sup>10+</sup>
on(type: 'dataProgress', callback: Callback
\<
{ receiveSize: number, totalSize: number }
\>
): void
订阅HTTP流式响应数据接收进度事件。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | --------------------------------- |
| type | string | 是 | 订阅的事件类型,'dataProgress'。 |
| callback | AsyncCallback
\<
{ receiveSize: number, totalSize: number }
\>
| 是 | 回调函数。
<br>
receiveSize:已接收的数据字节数,totalSize待接收的字节总数 |
**示例:**
```
js
httpRequest
.
on
(
'
dataProgress
'
,
(
data
)
=>
{
console
.
info
(
'
dataProgress:
'
+
JSON
.
stringify
(
data
));
});
```
### off('dataProgress')<sup>10+</sup>
off(type: 'dataProgress', callback?: Callback
\<
{ receiveSize: number, totalSize: number }
\>
): void
取消订阅HTTP流式响应数据接收进度事件。
>**说明:**
>可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------ | ---- | -------------------------------------- |
| type | string | 是 | 取消订阅的事件类型:'dataProgress'。 |
| callback | Callback
\<
{ receiveSize: number, totalSize: number }
\>
| 否 | 回调函数。 |
**示例:**
```
js
httpRequest
.
off
(
'
dataProgress
'
);
```
## HttpRequestOptions
## HttpRequestOptions
发起请求可选参数的类型和取值范围。
发起请求可选参数的类型和取值范围。
...
@@ -812,7 +471,6 @@ httpRequest.off('dataProgress');
...
@@ -812,7 +471,6 @@ httpRequest.off('dataProgress');
| readTimeout | number | 否 | 读取超时时间。单位为毫秒(ms),默认为60000ms。 |
| readTimeout | number | 否 | 读取超时时间。单位为毫秒(ms),默认为60000ms。 |
| connectTimeout | number | 否 | 连接超时时间。单位为毫秒(ms),默认为60000ms。 |
| connectTimeout | number | 否 | 连接超时时间。单位为毫秒(ms),默认为60000ms。 |
| usingProtocol<sup>9+</sup> | [HttpProtocol](#httpprotocol9) | 否 | 使用协议。默认值由系统自动指定。 |
| usingProtocol<sup>9+</sup> | [HttpProtocol](#httpprotocol9) | 否 | 使用协议。默认值由系统自动指定。 |
| usingProxy
<sup>
10+
</sup>
| boolean
\|
Object | 否 | 是否使用HTTP代理,默认为false,不使用代理。
<br
/>
- 当usingProxy为布尔类型true时,使用默认网络代理。
<br
/>
- 当usingProxy为object类型时,使用指定网络代理。 |
## RequestMethod
## RequestMethod
...
...
zh-cn/application-dev/reference/apis/js-apis-net-connection.md
浏览文件 @
dbdfb789
...
@@ -140,167 +140,6 @@ getDefaultNetSync(): NetHandle
...
@@ -140,167 +140,6 @@ getDefaultNetSync(): NetHandle
let
netHandle
=
connection
.
getDefaultNetSync
();
let
netHandle
=
connection
.
getDefaultNetSync
();
```
```
## connection.getGlobalHttpProxy<sup>10+</sup>
getGlobalHttpProxy(callback: AsyncCallback
\<
HttpProxy>): void
获取网络的全局代理配置信息,使用callback方式作为异步方法。
**系统接口**
:此接口为系统接口。
**系统能力**
:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------------------------ | ---- | ---------------- |
| callback | AsyncCallback
\<
[
HttpProxy
](
#httpproxy
)
> | 是 | 回调函数。当成功获取网络的全局代理配置信息时,err为undefined,data为网络的全局代理配置信息;否则为错误对象|
**错误码:**
| 错误码ID | 错误信息 |
| ------- | ----------------------------- |
| 2100002 | Operation failed. Cannot connect to service.|
| 2100003 | System internal error. |
**示例:**
```
js
connection
.
getGlobalHttpProxy
((
error
,
data
)
=>
{
console
.
info
(
JSON
.
stringify
(
error
));
console
.
info
(
JSON
.
stringify
(
data
));
})
```
## connection.getGlobalHttpProxy<sup>10+</sup>
getGlobalHttpProxy(): Promise
\<
HttpProxy>;
获取网络的全局代理配置信息,使用Promise方式作为异步方法。
**系统接口**
:此接口为系统接口。
**系统能力**
:SystemCapability.Communication.NetManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ------------------------------------- |
| Promise
\<
[
HttpProxy
](
#httpproxy
)
> | 以Promise形式返回网络的全局代理配置信息。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | ----------------------------- |
| 2100002 | Operation failed. Cannot connect to service.|
| 2100003 | System internal error. |
**示例:**
```
js
connection
.
getGlobalHttpProxy
().
then
((
data
)
=>
{
console
.
info
(
JSON
.
stringify
(
data
));
}).
catch
(
error
=>
{
console
.
info
(
JSON
.
stringify
(
error
));
})
```
## connection.setGlobalHttpProxy<sup>10+</sup>
setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback
\<
void>): void
设置网络全局Http代理配置信息,使用callback方式作为异步方法。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**
:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------------------------ | ---- | ---------------- |
| httpProxy |
[
HttpProxy
](
#httpproxy
)
| 是 | 网络全局Http代理配置信息 |
| callback | AsyncCallback
\<
void> | 是 | 回调函数。当成功设置网络全局Http代理配置信息时,err为undefined,否则为错误对象|
**错误码:**
| 错误码ID | 错误信息 |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 401 | Parameter error. |
| 2100001 | Invalid parameter value. |
| 2100002 | Operation failed. Cannot connect to service.|
| 2100003 | System internal error. |
**示例:**
```
js
let
exclusionStr
=
"
192.168,baidu.com
"
let
exclusionArray
=
exclusionStr
.
split
(
'
,
'
);
let
httpProxy
=
{
host
:
"
192.168.xx.xxx
"
,
port
:
8080
,
exclusionList
:
exclusionArray
}
connection
.
setGlobalHttpProxy
(
httpProxy
,
(
error
,
data
)
=>
{
console
.
info
(
JSON
.
stringify
(
error
));
console
.
info
(
JSON
.
stringify
(
data
));
});
```
## connection.setGlobalHttpProxy<sup>10+</sup>
setGlobalHttpProxy(httpProxy: HttpProxy): Promise
\<
void>;
设置网络全局Http代理配置信息,使用Promise方式作为异步方法。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**
:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------------------------ | ---- | ---------------- |
| httpProxy |
[
HttpProxy
](
#httpproxy
)
| 是 | 网络全局Http代理配置信息。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------- | ----------------------------- |
| Promise
\<
void> | 无返回值的Promise对象。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 401 | Parameter error. |
| 2100001 | Invalid parameter value. |
| 2100002 | Operation failed. Cannot connect to service.|
| 2100003 | System internal error. |
**示例:**
```
js
let
exclusionStr
=
"
192.168,baidu.com
"
let
exclusionArray
=
exclusionStr
.
split
(
'
,
'
);
let
httpProxy
=
{
host
:
"
192.168.xx.xxx
"
,
port
:
8080
,
exclusionList
:
exclusionArray
}
connection
.
setGlobalHttpProxy
(
httpProxy
).
then
(()
=>
{
console
.
info
(
"
success
"
);
}).
catch
(
error
=>
{
console
.
info
(
JSON
.
stringify
(
error
));
})
```
## connection.getAppNet<sup>9+</sup>
## connection.getAppNet<sup>9+</sup>
getAppNet(callback: AsyncCallback
\<
NetHandle>): void
getAppNet(callback: AsyncCallback
\<
NetHandle>): void
...
@@ -1823,18 +1662,6 @@ connection.getDefaultNet().then(function (netHandle) {
...
@@ -1823,18 +1662,6 @@ connection.getDefaultNet().then(function (netHandle) {
| BEARER_WIFI | 1 | Wi-Fi网络。 |
| BEARER_WIFI | 1 | Wi-Fi网络。 |
| BEARER_ETHERNET | 3 | 以太网网络。 |
| BEARER_ETHERNET | 3 | 以太网网络。 |
## HttpProxy<sup>10+</sup>
网络全局代理配置信息
**系统能力**
:SystemCapability.Communication.NetManager.Core
| 名称 | 类型 | 必填 | 说明 |
| ------ | ------ | --- |------------------------- |
| host | string | 否 | 代理服务器主机名。 |
| port | number | 否 | 主机端口。 |
| exclusionList | Array
<string>
| 否 | 不使用代理服务器的屏蔽列表。 |
## NetSpecifier
## NetSpecifier
提供承载数据网络能力的实例。
提供承载数据网络能力的实例。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录