# @ohos.net.connection (Network Connection Management) (System API)
The network connection management module provides basic network management capabilities. You can obtain the default active data network or the list of all active data networks, enable or disable the airplane mode, and obtain network capability information.
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.net.connection (Network Connection Management)](js-apis-net-connection.md).
## Modules to Import
```ts
import { connection } from '@kit.NetworkKit';
```
## connection.getGlobalHttpProxy10+
getGlobalHttpProxy(callback: AsyncCallback\): void
Obtains the global HTTP proxy configuration of the network. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<[HttpProxy](js-apis-net-connection.md#httpproxy10)> | Yes | Callback used to return the result. If the global HTTP proxy configuration of the network is obtained successfully, **error** is **undefined** and **data** is the global HTTP proxy configuration. Otherwise, **error** is an error object.|
**Error codes**
| ID| Error Message |
| ------- | ----------------------------- |
| 401 | Parameter error. |
| 202 | Non-system applications use system APIs. |
| 2100002 | Failed to connect to the service.|
| 2100003 | System internal error. |
**Example**
```ts
import { connection } from '@kit.NetworkKit';
import { BusinessError } from '@kit.BasicServicesKit';
connection.getGlobalHttpProxy((error: BusinessError, data: connection.HttpProxy) => {
console.info(JSON.stringify(error));
console.info(JSON.stringify(data));
});
```
## connection.getGlobalHttpProxy10+
getGlobalHttpProxy(): Promise\;
Obtains the global HTTP proxy configuration of the network. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<[HttpProxy](js-apis-net-connection.md#httpproxy10)> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| ------- | ----------------------------- |
| 202 | Non-system applications use system APIs. |
| 2100002 | Failed to connect to the service.|
| 2100003 | System internal error. |
**Example**
```ts
import { connection } from '@kit.NetworkKit';
import { BusinessError } from '@kit.BasicServicesKit';
connection.getGlobalHttpProxy().then((data: connection.HttpProxy) => {
console.info(JSON.stringify(data));
}).catch((error: BusinessError) => {
console.info(JSON.stringify(error));
});
```
## connection.setGlobalHttpProxy10+
setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback\): void
Sets the global HTTP proxy configuration of the network. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ------------------------------------------------------------ |
| httpProxy | [HttpProxy](js-apis-net-connection.md#httpproxy10) | Yes | Global HTTP proxy configuration of the network. |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the global HTTP proxy configuration of the network is set successfully, **error** is **undefined**. Otherwise, **error** is an error object.|
**Error codes**
| ID| Error Message |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 401 | Parameter error. |
| 202 | Non-system applications use system APIs. |
| 2100001 | Invalid parameter value. |
| 2100002 | Failed to connect to the service.|
| 2100003 | System internal error. |
**Example**
```ts
import { connection } from '@kit.NetworkKit';
import { BusinessError } from '@kit.BasicServicesKit';
let exclusionStr = "192.168,baidu.com";
let exclusionArray = exclusionStr.split(',');
let httpProxy: connection.HttpProxy = {
host: "192.168.xx.xxx",
port: 8080,
exclusionList: exclusionArray
}
connection.setGlobalHttpProxy(httpProxy, (err: BusinessError) => {
if (err) {
console.error(`setGlobalHttpProxy failed, callback: err->${JSON.stringify(err)}`);
return;
}
console.log(`setGlobalHttpProxy success.`);
});
```
## connection.setGlobalHttpProxy10+
setGlobalHttpProxy(httpProxy: HttpProxy): Promise\;
Sets the global HTTP proxy configuration of the network. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------------------------------------------ | ---- | ---------------- |
| httpProxy | [HttpProxy](js-apis-net-connection.md#httpproxy10) | Yes | Global HTTP proxy configuration of the network.|
**Return value**
| Type | Description |
| ------------------------------------------- | ----------------------------- |
| Promise\ | Promise that returns no value.|
**Error codes**
| ID| Error Message |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 401 | Parameter error. |
| 202 | Non-system applications use system APIs. |
| 2100001 | Invalid parameter value. |
| 2100002 | Failed to connect to the service.|
| 2100003 | System internal error. |
**Example**
```ts
import { connection } from '@kit.NetworkKit';
import { BusinessError } from '@kit.BasicServicesKit';
let exclusionStr = "192.168,baidu.com";
let exclusionArray = exclusionStr.split(',');
connection.setGlobalHttpProxy({
host: "192.168.xx.xxx",
port: 8080,
exclusionList: exclusionArray
} as connection.HttpProxy).then(() => {
console.info("success");
}).catch((error: BusinessError) => {
console.info(JSON.stringify(error));
});
```
## connection.enableAirplaneMode
enableAirplaneMode(callback: AsyncCallback\): void
Enables the airplane mode. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------ |
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
**Error codes**
| ID| Error Message |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 401 | Parameter error. |
| 2100002 | Failed to connect to the service.|
| 2100003 | System internal error. |
**Example**
```ts
import { connection } from '@kit.NetworkKit';
import { BusinessError } from '@kit.BasicServicesKit';
connection.enableAirplaneMode((error: BusinessError) => {
console.log(JSON.stringify(error));
});
```
## connection.enableAirplaneMode
enableAirplaneMode(): Promise\
Enables the airplane mode. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| ------------------------------------------- | ----------------------------- |
| Promise\ | Promise that returns no value.|
**Error codes**
| ID| Error Message |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 2100002 | Failed to connect to the service.|
| 2100003 | System internal error. |
**Example**
```ts
import { connection } from '@kit.NetworkKit';
connection.enableAirplaneMode().then((error: void) => {
console.log(JSON.stringify(error));
});
```
## connection.disableAirplaneMode
disableAirplaneMode(callback: AsyncCallback\): void
Disables the airplane mode. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------ |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the airplane mode is disabled successfully, **error** is **undefined**. Otherwise, **error** is an error object.|
**Error codes**
| ID| Error Message |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 401 | Parameter error. |
| 2100002 | Failed to connect to the service.|
| 2100003 | System internal error. |
**Example**
```ts
import { connection } from '@kit.NetworkKit';
import { BusinessError } from '@kit.BasicServicesKit';
connection.disableAirplaneMode((error: BusinessError) => {
console.log(JSON.stringify(error));
});
```
## connection.disableAirplaneMode
disableAirplaneMode(): Promise\
Disables the airplane mode. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| ------------------------------------------- | ----------------------------- |
| Promise\ | Promise that returns no value.|
**Error codes**
| ID| Error Message |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 2100002 | Failed to connect to the service.|
| 2100003 | System internal error. |
**Example**
```ts
import { connection } from '@kit.NetworkKit';
connection.disableAirplaneMode().then((error: void) => {
console.log(JSON.stringify(error));
});
```
## connection.factoryReset11+
factoryReset(): Promise\
Resets the network settings to factory defaults. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| ---------------------- | ----------------------- |
| Promise\ | Promise that returns no value. |
**Error codes**
| ID| Error Message |
| ------- | ------------------------------------------ |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 2100002 | Failed to connect to the service.|
| 2100003 | System internal error. |
**Example**
```ts
import { connection } from '@kit.NetworkKit';
import { BusinessError } from '@kit.BasicServicesKit';
connection.factoryReset().then(() => {
console.log("success");
}).catch((error: BusinessError) => {
console.log(JSON.stringify(error));
})
```