美文网首页
HarmonyOS 数据请求

HarmonyOS 数据请求

作者: 张思学 | 来源:发表于2024-08-15 09:56 被阅读0次

应用通过HTTP发起一个数据请求,支持常见的GET、POST、OPTIONS、HEAD、PUT、DELETE、TRACE、CONNECT方法。
使用该功能需要申请ohos.permission.INTERNET权限。

接口说明

image.png

请求接口封装

ets > common > utils > HttpUtil.est

import { http } from '@kit.NetworkKit';

export default async function https(url: string, method: string) {
  if (!url) {
    return undefined;
  }
  let request = http.createHttp();

  let result = await request.request(url, {
    method: method as http.RequestMethod,
    header: { 'Content-Type': 'application/json' },
    readTimeout: 50000,
    connectTimeout:50000
  });
  request.destroy();
  return result.result
}

相关文章

网友评论

      本文标题:HarmonyOS 数据请求

      本文链接:https://www.haomeiwen.com/subject/kmjskjtx.html