diff --git a/README.en.md b/README.en.md index 79af9417d3d7e54f054b84d7a13850151f88385d..6ba748962625739f1dfd1561db10c26f236ee3b3 100644 --- a/README.en.md +++ b/README.en.md @@ -4,7 +4,7 @@ Based on the network module, learn how to implement secure, encrypted data transmission. -![](screenshots/device/https.en.gif) +![](screenshots/device/https_en.png) ### Concepts diff --git a/README.md b/README.md index 5a366ea7f31e896aaa2cabb09e8305b144f33597..15dd450a91cb5571085b6285ed0282cc7caf2834 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ 基于网络模块,实现数据安全加密传输。 -![](screenshots/device/https.gif) +![](screenshots/device/https_cn.png) ### 相关概念 diff --git a/entry/src/main/ets/common/constant/CommonConstants.ets b/entry/src/main/ets/common/constant/CommonConstants.ets index 622cfc8e5bf48006df8bdc479b18f517ec0fae27..dee9a7bdc6fd53146e1c593ffcb49c814b1b36b3 100644 --- a/entry/src/main/ets/common/constant/CommonConstants.ets +++ b/entry/src/main/ets/common/constant/CommonConstants.ets @@ -17,7 +17,7 @@ export default class CommonConstant { /** * The host address of the server. */ - static readonly SERVER: string = 'https://www.harmonyos.com'; + static readonly SERVER: Resource = $r('app.string.server_address'); /** * The request success code. diff --git a/entry/src/main/ets/pages/WebPage.ets b/entry/src/main/ets/pages/WebPage.ets index be3c27c4a2482ea54117761fab9d548d5b46bb8f..20ac8bbf7c7b22d8ed775a9eb650a23806891d49 100644 --- a/entry/src/main/ets/pages/WebPage.ets +++ b/entry/src/main/ets/pages/WebPage.ets @@ -13,13 +13,17 @@ * limitations under the License. */ +import { hilog } from '@kit.PerformanceAnalysisKit'; import { webview } from '@kit.ArkWeb'; import { http } from '@kit.NetworkKit'; -import { promptAction } from '@kit.ArkUI'; import httpGet from '../common/utils/HttpUtil'; import StyleConstant from '../common/constant/StyleConstant'; import CommonConstant from '../common/constant/CommonConstants'; +const DOMAIN = 0x0000; +const TAG = 'WebPage'; +const FORMAT = '%{public}s'; + @Entry @Component struct WebPage { @@ -27,7 +31,7 @@ struct WebPage { @StorageLink('bottomHeight') bottomHeight: number = 0; @State buttonName: Resource = $r('app.string.request_button_name'); @State webVisibility: Visibility = Visibility.Hidden; - @State webSrc: string = CommonConstant.SERVER; + @State webSrc: ResourceStr = CommonConstant.SERVER; controller: webview.WebviewController = new webview.WebviewController(); build() { @@ -94,7 +98,7 @@ struct WebPage { if (this.webVisibility === Visibility.Hidden) { this.webVisibility = Visibility.Visible; try { - let result = await httpGet(this.webSrc); + let result = await httpGet(this.getResourceString(this.webSrc as Resource)); if (result && result.responseCode === http.ResponseCode.OK) { this.controller.clearHistory(); this.controller.loadUrl(this.webSrc); @@ -108,4 +112,14 @@ struct WebPage { this.webVisibility = Visibility.Hidden; } } + + getResourceString(resource: Resource): string { + let resourceString: string = ''; + try { + resourceString = this.getUIContext().getHostContext()!.resourceManager.getStringSync(resource.id); + } catch (err) { + hilog.error(DOMAIN, TAG, FORMAT, `Failed to getResourceString. Cause code: ${err.code},message: ${err.message}`); + } + return resourceString; + } } \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 6bac6d55fd3afc545f480faaa6a4c8b1405b1355..bceab5003595a022163a3fc5b09a7db47dcafc57 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -35,6 +35,10 @@ { "name": "reason", "value": "Allow applications to access web pages using the Internet network." + }, + { + "name": "server_address", + "value": "https://www.harmonyos.com/en/" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index 6bac6d55fd3afc545f480faaa6a4c8b1405b1355..bceab5003595a022163a3fc5b09a7db47dcafc57 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -35,6 +35,10 @@ { "name": "reason", "value": "Allow applications to access web pages using the Internet network." + }, + { + "name": "server_address", + "value": "https://www.harmonyos.com/en/" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 7774154433d4e99f8ab4b8c233c6f96a9fbb2599..3d79a8a26bb42e207ec056672d208ae464c13487 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -35,6 +35,10 @@ { "name": "reason", "value": "允许访问网页场景使用Internet网络。" + }, + { + "name": "server_address", + "value": "https://www.harmonyos.com/" } ] } \ No newline at end of file diff --git a/screenshots/device/https.gif b/screenshots/device/https.gif deleted file mode 100644 index e9ba9e6d4437062d660bd1747af937d437b061c6..0000000000000000000000000000000000000000 Binary files a/screenshots/device/https.gif and /dev/null differ diff --git a/screenshots/device/https_cn.png b/screenshots/device/https_cn.png new file mode 100644 index 0000000000000000000000000000000000000000..f27497307a1e4b1332176d876eb6b6fdccf13927 Binary files /dev/null and b/screenshots/device/https_cn.png differ diff --git a/screenshots/device/https_en.png b/screenshots/device/https_en.png new file mode 100644 index 0000000000000000000000000000000000000000..3ee0dc8a5ffb22c7fa1dc9dc9e6b4d640398b7bc Binary files /dev/null and b/screenshots/device/https_en.png differ