diff --git a/AppScope/app.json5 b/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7d048d5e0aaec5caec85571616dbeaada80b21d7 --- /dev/null +++ b/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.httpsrequest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/AppScope/resources/base/element/string.json b/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..14ab13c15a732d45a2337afb03696dab691f5619 --- /dev/null +++ b/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "HttpsRequest" + } + ] +} diff --git a/AppScope/resources/base/media/app_icon.png b/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/AppScope/resources/base/media/app_icon.png differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..0210352ae2ade0dd7b4c841cb6e8ba08b4780038 --- /dev/null +++ b/LICENSE @@ -0,0 +1,78 @@ + Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Apache License, Version 2.0 +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: +1.You must give any other recipients of the Work or Derivative Works a copy of this License; and +2.You must cause any modified files to carry prominent notices stating that You changed the files; and +3.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +4.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 0ef4ee590adb5172b2a92c2252f318b668677702..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# HttpsRequest - -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index fd1daa845295c2b7d349a0b238444d802ec21fe9..0dc7bd55ef7637d0fe5cbd2c83e2831ec98570cd 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,30 @@ -# HttpsRequest +# 网络-HTTPS请求过程 -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +### 简介 -#### 软件架构 -软件架构说明 +基于网络模块,实现数据安全加密传输。 +![](screenshots/device/https.gif) -#### 安装教程 +### 相关概念 -1. xxxx -2. xxxx -3. xxxx +- Webview:提供Web控制能力,Web组件提供网页显示能力。 +- HTTP数据请求:网络管理模块,提供HTTP数据请求能力,支持GET、POST、OPTIONS、HEAD、PUT、DELETE、TRACE、CONNECT请求方法。 +- HTTPS:应用层协议,支持加密传输以及身份认证,保证数据的安全传输。 +- SSL:SSL(Secure Socket Layer)安全套接层是位于传输通信协议(TCP/IP)之上实现的一种安全协议。 +- TLS:TLS(Transport Layer Security)是一种安全协议,旨在实现数据加密传输。 -#### 使用说明 +### 相关权限 -1. xxxx -2. xxxx -3. xxxx +不涉及 -#### 参与贡献 +### 使用说明 -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +1. 如何使用@kit.NetworkKit进行https请求。 +### 约束与限制 -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 +2. HarmonyOS系统:HarmonyOS NEXT Developer Beta1及以上。 +3. DevEco Studio版本:DevEco Studio NEXT Developer Beta1及以上。 +4. HarmonyOS SDK版本:HarmonyOS NEXT Developer Beta1 SDK及以上。 diff --git a/build-profile.json5 b/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1d12140d202702d7c73d64f1b291fe5c45a660ce --- /dev/null +++ b/build-profile.json5 @@ -0,0 +1,27 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..13c5eda6e6a3dae913ec5c5c4d60ea3ac954f205 --- /dev/null +++ b/entry/build-profile.json5 @@ -0,0 +1,11 @@ +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "HarmonyOS" + } + ] +} \ No newline at end of file diff --git a/entry/hvigorfile.ts b/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..80e4ec5b81689f238c34614b167a0b9e9c83e8d9 --- /dev/null +++ b/entry/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..225946cb11a2c405c8dc81eea89c22f923556638 --- /dev/null +++ b/entry/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/entry/src/main/ets/common/constant/CommonConstants.ets b/entry/src/main/ets/common/constant/CommonConstants.ets new file mode 100644 index 0000000000000000000000000000000000000000..622cfc8e5bf48006df8bdc479b18f517ec0fae27 --- /dev/null +++ b/entry/src/main/ets/common/constant/CommonConstants.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default class CommonConstant { + /** + * The host address of the server. + */ + static readonly SERVER: string = 'https://www.harmonyos.com'; + + /** + * The request success code. + */ + static readonly SUCCESS_CODE: number = 200; + + /** + * Read timeout. + */ + static readonly READ_TIMEOUT: number = 50000; + + /** + * Connect timeout. + */ + static readonly CONNECT_TIMEOUT: number = 50000; +} \ No newline at end of file diff --git a/entry/src/main/ets/common/constant/StyleConstant.ets b/entry/src/main/ets/common/constant/StyleConstant.ets new file mode 100644 index 0000000000000000000000000000000000000000..74eade926973357522964b54d78bf41af4ce2fe8 --- /dev/null +++ b/entry/src/main/ets/common/constant/StyleConstant.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default class StyleConstants { + /** + * Full the width. + */ + static readonly FULL_WIDTH: string = '100%'; + + /** + * Full the height. + */ + static readonly FULL_HEIGHT: string = '100%'; + + /** + * Web height. + */ + static readonly WEB_HEIGHT: string = '83%'; + + /** + * Button width. + */ + static readonly BUTTON_WIDTH: string = '90%'; +} \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/HttpUtil.ets b/entry/src/main/ets/common/utils/HttpUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..0e251f59116e5251ea739e877317f619496644ff --- /dev/null +++ b/entry/src/main/ets/common/utils/HttpUtil.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { http } from '@kit.NetworkKit'; +import CommonConstant from '../constant/CommonConstants'; + +/** + * Initiates an HTTP request to a given URL. + * + * @param url URL for initiating an HTTP request. + * @returns the result of HTTPS. + */ +export default async function httpGet(url: string) { + if (!url) { + return undefined; + } + let request = http.createHttp(); + + let result = await request.request(url, { + method: http.RequestMethod.GET, + header: { 'Content-Type': 'application/json' }, + readTimeout: CommonConstant.READ_TIMEOUT, + connectTimeout: CommonConstant.CONNECT_TIMEOUT + }); + return result; +} \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/Logger.ets b/entry/src/main/ets/common/utils/Logger.ets new file mode 100644 index 0000000000000000000000000000000000000000..c72b97c5ca7f897d01c81af4d72f49523fdd495e --- /dev/null +++ b/entry/src/main/ets/common/utils/Logger.ets @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + /** + * constructor. + * + * @param Prefix Identifies the log tag. + * @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF. + */ + constructor(prefix: string = 'MyApp', domain: number = 0xFF00) { + this.prefix = prefix; + this.domain = domain; + } + + debug(...args: []): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: []): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: []): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: []): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + +export default new Logger('HTTPS', 0xFF00) \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..2573f3138fb5463e224cf4089951dd6d1d8b0968 --- /dev/null +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { UIAbility, Want, AbilityConstant } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + want: Want | undefined = undefined; + launchParam: AbilityConstant.LaunchParam | undefined = undefined; + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.want = want; + this.launchParam = launchParam; + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void | Promise { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/WebPage', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/WebPage.ets b/entry/src/main/ets/pages/WebPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..f7a109e00dbcf01cd2e0ab5e713952c863737b6c --- /dev/null +++ b/entry/src/main/ets/pages/WebPage.ets @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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'; + +@Entry +@Component +struct WebPage { + controller: webview.WebviewController = new webview.WebviewController(); + @State buttonName: Resource = $r('app.string.request_button_name'); + @State webVisibility: Visibility = Visibility.Hidden; + @State webSrc: string = CommonConstant.SERVER; + + build() { + Column() { + Row() { + Image($r('app.media.ic_network_global')) + .height($r('app.float.image_height')) + .width($r('app.float.image_width')) + TextInput({ placeholder: $r('app.string.input_address'), text: this.webSrc }) + .height($r('app.float.text_input_height')) + .layoutWeight(1) + .backgroundColor(Color.White) + .onChange((value: string) => { + this.webSrc = value; + }) + } + .margin({ + top: $r('app.float.default_margin'), + left: $r('app.float.default_margin'), + right: $r('app.float.default_margin') + }) + .height($r('app.float.default_row_height')) + .backgroundColor(Color.White) + .borderRadius($r('app.float.border_radius')) + .padding({ + left: $r('app.float.default_padding'), + right: $r('app.float.default_padding') + }) + Row() { + Web({ src: this.webSrc, controller: this.controller }) + .zoomAccess(true) + .height(StyleConstant.FULL_HEIGHT) + .width(StyleConstant.FULL_WIDTH) + } + .visibility(this.webVisibility) + .height(StyleConstant.WEB_HEIGHT) + .width(StyleConstant.FULL_WIDTH) + .align(Alignment.Top) + Row() { + Button(this.buttonName) + .fontSize($r('app.float.button_font_size')) + .width(StyleConstant.BUTTON_WIDTH) + .height($r('app.float.button_height')) + .fontWeight(FontWeight.Bold) + .onClick(() => { + this.onRequest(); + }) + } + .height($r('app.float.default_row_height')) + } + .width(StyleConstant.FULL_WIDTH) + .height(StyleConstant.FULL_HEIGHT) + .backgroundImage($r('app.media.ic_background_image', ImageRepeat.NoRepeat)) + .backgroundImageSize(ImageSize.Cover) + } + + async onRequest() { + if (this.webVisibility === Visibility.Hidden) { + this.webVisibility = Visibility.Visible; + try { + let result = await httpGet(this.webSrc); + if (result && result.responseCode === http.ResponseCode.OK) { + this.controller.clearHistory(); + this.controller.loadUrl(this.webSrc); + } + } catch (error) { + promptAction.showToast({ + message: $r('app.string.http_response_error') + }) + } + } else { + this.webVisibility = Visibility.Hidden; + } + } +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f60e9e772ec7509eeb0f5b25394c26cf8d350fb1 --- /dev/null +++ b/entry/src/main/module.json5 @@ -0,0 +1,48 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET", + "reason": "$string:reason", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + } + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/float.json b/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..8e30f46ca9e2200de7685d5ca3f51b6f3fb616ed --- /dev/null +++ b/entry/src/main/resources/base/element/float.json @@ -0,0 +1,48 @@ +{ + "float": [ + { + "name": "text_input_width", + "value": "300" + }, + { + "name": "button_font_size", + "value": "16" + }, + { + "name": "button_height", + "value": "40" + }, + { + "name": "text_input_height", + "value": "40" + }, + { + "name": "default_fontSize", + "value": "30" + }, + { + "name": "image_height", + "value": "30" + }, + { + "name": "image_width", + "value": "30" + }, + { + "name": "border_radius", + "value": "28" + }, + { + "name": "default_row_height", + "value": "56" + }, + { + "name": "default_margin", + "value": "12" + }, + { + "name": "default_padding", + "value": "12" + } + ] +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..814308c93cce45b0423bcb8dc3c113cdae17459c --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "HttpsRequest" + }, + { + "name": "http_error_message", + "value": "Network request failed, please try later!" + }, + { + "name": "request_button_name", + "value": "request" + }, + { + "name": "input_address", + "value": "Please input the address" + }, + { + "name": "request_success", + "value": "success" + }, + { + "name": "http_response_error", + "value": "Request error, please check if there is a network." + }, + { + "name": "reason", + "value": "Connect to the network." + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_background_image.png b/entry/src/main/resources/base/media/ic_background_image.png new file mode 100644 index 0000000000000000000000000000000000000000..5f69b9baaa51497f70aa57f37373e421fb669aa1 Binary files /dev/null and b/entry/src/main/resources/base/media/ic_background_image.png differ diff --git a/entry/src/main/resources/base/media/ic_network_global.png b/entry/src/main/resources/base/media/ic_network_global.png new file mode 100644 index 0000000000000000000000000000000000000000..13993ba206e9109640e51648fcd5b22ea5767bb4 Binary files /dev/null and b/entry/src/main/resources/base/media/ic_network_global.png differ diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/entry/src/main/resources/base/media/icon.png differ diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..d46d349982240e42a58c7157ef9a3ee10ab163f2 --- /dev/null +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/WebPage" + ] +} diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..814308c93cce45b0423bcb8dc3c113cdae17459c --- /dev/null +++ b/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "HttpsRequest" + }, + { + "name": "http_error_message", + "value": "Network request failed, please try later!" + }, + { + "name": "request_button_name", + "value": "request" + }, + { + "name": "input_address", + "value": "Please input the address" + }, + { + "name": "request_success", + "value": "success" + }, + { + "name": "http_response_error", + "value": "Request error, please check if there is a network." + }, + { + "name": "reason", + "value": "Connect to the network." + } + ] +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..1d8d63845bc7451f2cb9bb1668203c3bbe2f893f --- /dev/null +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "描述" + }, + { + "name": "EntryAbility_label", + "value": "https请求" + }, + { + "name": "http_error_message", + "value": "网络请求错误,请稍后重试!" + }, + { + "name": "request_button_name", + "value": "请求" + }, + { + "name": "input_address", + "value": "请输入网址" + }, + { + "name": "request_success", + "value": "成功" + }, + { + "name": "http_response_error", + "value": "请求出错,请检查是否有网络" + }, + { + "name": "reason", + "value": "Connect to the network." + } + ] +} \ No newline at end of file diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..73bfab4e997c8d4aea53b22fdd7f10112b30987f --- /dev/null +++ b/hvigor/hvigor-config.json5 @@ -0,0 +1,17 @@ +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } +} \ No newline at end of file diff --git a/hvigorfile.ts b/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6478186902c0c1ad7c966a929c7d6b7d8ae7a9f3 --- /dev/null +++ b/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { appTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/oh-package.json5 b/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fa57132b9110be9c7ece6ef24c669a4f302cc572 --- /dev/null +++ b/oh-package.json5 @@ -0,0 +1,12 @@ +{ + "modelVersion": "5.0.0", + "license": "", + "devDependencies": { + }, + "author": "", + "name": "httpsrequest", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} \ No newline at end of file diff --git a/screenshots/device/https.gif b/screenshots/device/https.gif new file mode 100644 index 0000000000000000000000000000000000000000..e9ba9e6d4437062d660bd1747af937d437b061c6 Binary files /dev/null and b/screenshots/device/https.gif differ