准备资料接口准备准备get请求接
文章插图
Post接口
文章插图
如何集成在项目级别的build.gradle添加如下代码
<pre class="prettyprint hljs Nginx" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">allprojects {repositories {maven {url 'https://repo.huaweicloud.com/repository/maven/'}maven {url 'https://developer.huawei.com/repo/'</pre>
在entry的build.gradle添加如下代码<pre class="prettyprint hljs delphi" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">'io.openharmony.tpc.thirdlib:okgo:1.0.2'implementation 'io.openharmony.tpc.thirdlib:okrx:1.0.2'implementation 'io.openharmony.tpc.thirdlib:okrx2:1.0.2'implementation 'io.openharmony.tpc.thirdlib:okserver:1.0.2'</pre>
在entry的config.json添加 权限 ? 代码如下<pre class="prettyprint hljs lua" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">"reqPermissions": [{"name": "ohos.permission.INTE.NET"</pre>
注意事项如果接口是https的话需要在config.json的deviceConfig里添加如下代码<pre class="prettyprint hljs lua" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">"deviceConfig": {"default": {"network": {"cleartextTraffic": true</pre>
界面实现在layout的xml中写三个Text标签,第一个Text用于触发get请求的事件,第二个Text用于触发Post请求的事件,第三个Text用于显示结果,代码和效果图如下<pre class="prettyprint hljs vim" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><?xml version="1.0" encoding="utf-8"?><DirectionalLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:alignment="horizontal_center"ohos:orientation="vertical"><Textohos:id="$+id:text_type_get"ohos:height="100vp"ohos:width="match_parent"ohos:text_alignment="center"ohos:layout_alignment="horizontal_center"ohos:text="Get请求"ohos:text_size="40vp"<Textohos:id="$+id:text_type_Post"ohos:height="100vp"ohos:text_alignment="center"ohos:width="match_parent"ohos:background_element="#ed6262"ohos:layout_alignment="horizontal_center"ohos:text="Post请求"ohos:text_size="40vp"<Textohos:id="$+id:text_result"ohos:height="match_parent"ohos:multiple_lines="true"ohos:text_alignment="center"ohos:width="match_parent"ohos:layout_alignment="horizontal_center"ohos:text="显示结果"ohos:text_size="40vp"</DirectionalLayout></pre>
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 翡翠|「吴中博物馆」珍藏的整套晚清翡翠,打破大众对老翡翠的固有认知
- 短发|孙艺珍脸圆了,「肩上短发」待产新造型美翻
- |你身上是否有管理者潜质?「上」
- iPhone 一键「降级」iOS 4,效果绝了
- 义务教育数学课程标准(「数字化学习」)
- 智能硬件|HarmonyOS 3再升级:墨水平板与手机一拉即合
- 18个步骤 关闭Harmony OS系统自带广告
- 智能手表|华为Watch 3用上HarmonyOS 3:轻轻一拉即可互联协同
- 医美|海报试用 | 新升级的「虫草粉底」在“养肤”路上越走越光彩了?
- 「Java」封装的实现,访问限定符、包