小说网站如何建设门户网站建设和推广

张小明 2026/1/13 8:58:49
小说网站如何建设,门户网站建设和推广,海拉尔网站建设+网站设计,十大网站黄页的免费使用说明创建文件#xff1a;在 entry/src/main/ets/pages/ 目录下创建 NetworkDemo.ets或者直接替换现有页面的代码配置权限#xff1a;在 module.json5 中添加网络权限#xff08;如上所示#xff09;运行应用#xff1a;点击测试GET请求按钮发送HTTP请求点…使用说明创建文件在entry/src/main/ets/pages/目录下创建NetworkDemo.ets或者直接替换现有页面的代码配置权限在module.json5中添加网络权限如上所示运行应用点击测试GET请求按钮发送HTTP请求点击检查网络状态测试网络连通性点击清除数据清空显示内容核心功能说明网络请求使用ohos.net.http模块发送HTTP GET请求状态管理使用State装饰器管理UI状态异步处理使用async/await处理异步网络请求错误处理完整的异常捕获和处理机制UI反馈加载状态提示和结果显示部分代码// NetworkDemo.ets - HarmonyOS网络功能示例 import http from ohos.net.http; import common from ohos.app.ability.common; import { BusinessError } from ohos.base; // 定义Http请求选项的接口 interface HttpRequestOptions { method: http.RequestMethod; header?: Recordstring, string; connectTimeout?: number; readTimeout?: number; extraData?: string | Object; } // 定义API响应数据结构 interface ApiResponse { userId: number; id: number; title: string; body: string; } // 定义错误信息数据结构 interface ErrorInfo { code?: number; message?: string; stack?: string; name?: string; } Entry Component struct NetworkDemo { State message: string 点击按钮测试网络连接; State responseData: string ; State isConnected: boolean false; // 获取Ability上下文 private context getContext(this) as common.UIAbilityContext; build() { Column({ space: 20 }) { // 显示状态信息 Text(this.message) .fontSize(20) .fontColor(Color.Blue) .margin({ top: 30 }) // 显示连接状态 Text(this.isConnected ? 网络已连接 : 网络未连接) .fontSize(18) .fontColor(this.isConnected ? Color.Green : Color.Red) // 显示响应数据 Scroll() { Text(this.responseData) .fontSize(14) .textAlign(TextAlign.Start) .padding(10) } .height(200) .width(90%) .border({ width: 1, color: Color.Gray }) // 功能按钮区域 Column({ space: 15 }) { // 测试GET请求 Button(测试GET请求) .width(80%) .height(40) .onClick(() { this.testGetRequest(); }) // 测试连接状态 Button(检查网络状态) .width(80%) .height(40) .onClick(() { this.checkNetworkStatus(); }) // 清除数据 Button(清除数据) .width(80%) .height(40) .onClick(() { this.clearData(); }) } .width(100%) .margin({ top: 20 }) // 进度指示器 LoadingProgress() .color(Color.Blue) .visibility(this.message.includes(请求中) ? Visibility.Visible : Visibility.Hidden) } .width(100%) .height(100%) .padding(20) .justifyContent(FlexAlign.Start) } // 测试GET请求 private async testGetRequest() { this.message 正在发送请求...; this.responseData ; try { // 创建HTTP请求 let httpRequest http.createHttp(); // 设置请求参数 - 使用明确定义的类型 let url https://jsonplaceholder.typicode.com/posts/1; // 免费测试API let options: HttpRequestOptions { method: http.RequestMethod.GET, header: { Content-Type: application/json }, connectTimeout: 60000, readTimeout: 60000 }; // 发送请求 let response await httpRequest.request(url, options); // 检查响应状态 if (response.responseCode 200) { this.message 请求成功; this.isConnected true; // 安全地处理响应数据 try { const result response.result as string; const parsedData: ApiResponse JSON.parse(result) as ApiResponse; this.responseData JSON.stringify(parsedData, null, 2); } catch (parseError) { this.responseData response.result as string; } } else { this.message 请求失败: ${response.responseCode}; this.isConnected false; this.responseData response.result ? response.result as string : 无响应数据; } // 释放资源 httpRequest.destroy(); } catch (error) { // 使用BusinessError类型处理错误 const businessError error as BusinessError; this.message 请求异常: ${businessError.message || 未知错误}; this.isConnected false; // 安全地序列化错误对象 - 使用明确定义的类型 try { const errorObj: ErrorInfo { code: businessError.code, message: businessError.message, stack: businessError.stack, name: BusinessError }; this.responseData JSON.stringify(errorObj, null, 2); } catch (stringifyError) { const stringifyErr stringifyError as Error; this.responseData 错误信息: ${businessError.message || 未知错误}\n序列化错误: ${stringifyErr.message}; } } } // 检查网络状态 private async checkNetworkStatus() { try { // 简单的连接性检查 let httpRequest http.createHttp(); // 使用明确定义的类型 let options: HttpRequestOptions { method: http.RequestMethod.GET, connectTimeout: 5000 }; await httpRequest.request(https://www.baidu.com, options); this.message 网络连接正常; this.isConnected true; httpRequest.destroy(); } catch (error) { const businessError error as BusinessError; this.message 网络连接失败: ${businessError.message || 请检查网络设置}; this.isConnected false; } } // 清除数据 private clearData() { this.responseData ; this.message 数据已清除点击按钮测试网络; } }入门鸿蒙开发又怕花冤枉钱?别错过!现在能免费系统学 -- 从 ArkTS 面向对象核心的类和对象、继承多态到吃透鸿蒙开发关键技能还能冲刺鸿蒙基础 高级开发者证书更惊喜的是考证成功还送好礼!快加入我的鸿蒙班一起从入门到精通班级链接:点击https://developer.huawei.com/consumer/cn/training/classDetail/b7365031334e4353a9a0fd6785bb0791?type1?ha_sourcehmosclassha_sourceId89000248免费进入
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

电子商务网站建设评估的指标有哪些?手机网站开发流程.

Java与PostgreSQL JDBC开发指南 1. Java开发环境概述 Java编程语言迅速成为需要为多平台创建应用程序的程序员的首选。Java应用程序可以在Windows、Unix和Linux操作系统平台上运行,而无需重新编译新的可执行文件。Java有三种编程平台可供选择: - J2SE(Java版本2标准版):…

张小明 2026/1/10 8:03:30 网站建设

做网站什么意思怎么重新设置wordpress

技术工具类文章仿写专家Prompt指南 【免费下载链接】LeagueAkari ✨兴趣使然的,功能全面的英雄联盟工具集。支持战绩查询、自动秒选等功能。基于 LCU API。 项目地址: https://gitcode.com/gh_mirrors/le/LeagueAkari 一、核心任务定义 你是一名专业的文章仿…

张小明 2026/1/8 7:29:04 网站建设

上海建设银行官网网站6北京考试学院网站首页

PyTorch-CUDA-v2.8镜像支持哪些显卡?NVIDIA全系列兼容列表 在深度学习项目中,最让人头疼的往往不是模型设计,而是环境配置——CUDA版本不匹配、cuDNN缺失、PyTorch与驱动冲突……这些问题常常让开发者耗费数小时甚至几天时间来“修环境”。而…

张小明 2026/1/7 23:22:57 网站建设

网站建设策划方案书下载做五金找订单查什么网站

XUnity自动翻译插件:从零开始的完整使用手册 【免费下载链接】XUnity.AutoTranslator 项目地址: https://gitcode.com/gh_mirrors/xu/XUnity.AutoTranslator 你是否曾因语言障碍而无法畅玩心爱的外文游戏?XUnity Auto Translator正是为解决这一痛…

张小明 2026/1/8 5:29:44 网站建设

广告去哪个网站做管理wordpress

最近和几位创业的朋友聊天,大家都在感慨:现在做企业,最难的不是找客户,而是找人、管人、用人。 “上个月刚招来的销售,培训了半个月,说不干就不干了。” “社保政策又调整了,财务部天天加班算这…

张小明 2026/1/8 12:27:38 网站建设

网站首页锚文本wordpress商城主题

BBDown使用指南:轻松下载B站高清视频的完整教程 【免费下载链接】BBDown Bilibili Downloader. 一款命令行式哔哩哔哩下载器. 项目地址: https://gitcode.com/gh_mirrors/bb/BBDown 还在为B站视频无法离线观看而烦恼吗?BBDown作为一款强大的命令行…

张小明 2026/1/9 5:49:55 网站建设