# HarmonyOS_Request **Repository Path**: ltyuancan/HarmonyOS_Request ## Basic Information - **Project Name**: HarmonyOS_Request - **Description**: 鸿蒙网络请求简单封装和使用 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-08-05 - **Last Updated**: 2021-08-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HarmonyOS_Request #### 介绍 鸿蒙网络请求简单封装和使用 #### 使用说明 要在子线程中使用网络请求: ``` @Override public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_main); mThread = new Thread(new Runnable() { @Override public void run() { // getRequest(); postRequest(); } }); mThread.start(); } ``` 1、GET请求 ``` private void getRequest() { String requestUrl = "https://sapi.k780.com"; HashMap params = new HashMap(); ZSONObject zsonObject = new RequestUtil().get(requestUrl, null); HiLog.info(LABEL,"%{public}s", zsonObject); } ``` 2、POST请求 ``` private void postRequest() { String requestUrl = "https://blog.changshanhuoshan.cn/web/blog/list"; HashMap params = new HashMap(); params.put("pageNum", "1"); params.put("pageSize", "10"); ZSONObject zsonObject = new RequestUtil().post(requestUrl, params); HiLog.info(LABEL,"%{public}s", zsonObject); } ```