# RemoteCommunicationKit_SampleCode_ArkTS **Repository Path**: dingjiazhi/remote-communication-kit_-sample-code_-arkts ## Basic Information - **Project Name**: RemoteCommunicationKit_SampleCode_ArkTS - **Description**: 本示例主要展示了如何实现基础URL测试、超时测试、断点续传的功能。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 5 - **Created**: 2025-07-24 - **Last Updated**: 2025-07-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 远场通信服务示例代码 ## 简介 Remote Communication Kit(远场通信服务)是华为提供的HTTP发起数据请求的NAPI封装。应用通过Remote Communication Kit可便捷快速地向服务器发起数据请求。 ## 开发前准备 - 在开发HarmonyOS应用前,先进行对应的开发环境安装与调试。 - 了解远场通信服务代码结构。 ## 效果预览 ![效果图](./screenshots/Main.png) ![基础URL测试](./screenshots/BaseAddress.png) ![超时测试](./screenshots/TimeOut.png) ![断点续传测试](./screenshots/TransferRange.png) ![拦截器测试](./screenshots/Interceptor.png) ![上传文件测试](./screenshots/UploadFile.png) ![使用证书测试](./screenshots/Certificate.png) ## 工程目录 ``` └── entry/src/main/ets ├── entryability │ └── FormAbility.ets // 表单 │ └── MainAbility.ets // UI Ability └── pages │ └── BaseAddress.ets // 基础URL测试页面 │ └── Certificate.ets // 使用证书测试页面 │ └── Interceptor.ets // 拦截器测试页面 │ └── MainPage.ets // 主界面 │ └── TimeOut.ets // 超时测试页面 │ └── TransferRange.ets // 断点续传页面 │ └── UploadFile.ets // 上传文件测试页面 └── utils └── FileSelectUtils.ets // 选择文件的工具 ``` ## 具体实现 本示例主要展示的基础URL测试、超时测试、断点续传、拦截器、上传文件、使用证书功能,对应的接口均在@hms.collaboration.rcp.d.ts中: - 基础URL(BaseAddress):SessionConfiguration{baseAddress?: URLOrString;}。 - 超时测试(TimeOut):TransferConfiguration{timeout?: Timeout;}。 - 断点续传(TransferRange):TransferRange{from?: number; to?: number;}。 - 拦截器(Interceptor):SessionConfiguration{interceptors?: Interceptor[];}。 - 上传文件(UploadFile):uploadFromFile(url: URLOrString, uploadFrom: UploadFromFile): Promise。 - 使用证书(Certificate):SecurityConfiguration {remoteValidation?: 'system' | 'skip' | CertificateAuthority | ValidationCallback;}。 以上业务使用时,需先import @kit.RemoteCommunicationKit,再根据自身需求对接口进行扩展使用,详细情况可以参考本用例中entry/src/main/pages下六个接口的实现。 ## 相关权限 本Demo需要使用Internet和查询指定应用信息的权限,请在配置文件module.json5中添加以下权限: 1. 允许使用Internet网络权限:ohos.permission.INTERNET 2. 允许应用获取数据网络信息:ohos.permission.GET_NETWORK_INFO 3. 查询指定应用信息权限:ohos.permission.GET_BUNDLE_INFO(可选) ## 使用说明 如果在运行该示例代码时,出现运行不了的情况,可尝试选择DevEco Studio菜单栏Build里面的Clean Project选项,来清理工程。 ## 约束与限制 1.本示例仅支持标准系统上运行,支持设备:华为手机。 2.HarmonyOS系统:HarmonyOS NEXT Developer Beta1及以上。 3.DevEco Studio版本:DevEco Studio NEXT Developer Beta1及以上。 4.HarmonyOS SDK版本:HarmonyOS NEXT Developer Beta1 SDK及以上。