当前位置: 首页 > web >正文

Arkts完成数据请求http以及使用axios第三方库

import http from '@ohos.net.http'
@Entry
@Component
struct HttpPage {@State message: string = 'Hello World'build() {Column({space:20}) {Row(){Button('发送http请求').onClick(()=>{let httpRequest = http.createHttp();httpRequest.request('https://zzgoodqc.cn/index.php/index/qus/getquestionlist',{method:http.RequestMethod.POST,extraData:{sn:'1001'}}).then(resp=>{console.log("resp=>",JSON.stringify(resp))if(resp.responseCode === 200){console.log(resp.result.toString())}}).catch(err=>{console.log('请求错误err=>',err)})})}}.width('100%').height('100%')}
}

以上是方案1:默认数据请求

方案二:使用axios第三方库请求接口

第一步:安装aixos,执行

ohpm install @ohos/axios

第二步:注意配置网络权限,在module.json5文件中

    "requestPermissions":[{"name": "ohos.permission.INTERNET"}],

第三步:类似vue,正常引入使用

import axios from  '@ohos/axios'
@Entry
@Component
struct HttpPage {@State message: string = 'Hello World'build() {Column({space:20}) {Row(){Button('发送axios请求').onClick(()=>{axios.post('https://zzgoodqc.cn/index.php/index/qus/getquestionlist',{sn:'1001'}).then(response=>{console.log("response=>",JSON.stringify( response))}).catch(err=>{console.log('err=>',err)})})}}.width('100%').height('100%')}
}

http://www.xdnf.cn/news/3033.html

相关文章:

  • 杭州数据库恢复公司之Dell服务器RAID5阵列两块硬盘损坏报警离线
  • 服务器远程超出最大连接数的解决方案是什么?
  • 如何创建并使用极狐GitLab 项目访问令牌?
  • 基于esp32的小区智能门禁集成系统设计和实现
  • BFS最短路
  • Vue + ECharts 实现多层极坐标环形图
  • 基于STM32、HAL库的ATECC508A安全验证及加密芯片驱动程序设计
  • java练习2
  • langchain 简单与ollama 关联使用
  • Thinkphp开发自适应职业学生证书查询系统职业资格等级会员证书管理网站
  • SMPP协议解析
  • mysql数据库连接数不足导致 Bean 注入失败
  • 4月28号
  • TCP三次握手
  • [TxRxResult] There is no status packet! 及 Incorrect status packet! 问题修复
  • 第一章 应急响应- Linux入侵排查
  • 文件基础-----C语言经典题目(11)
  • 前端vue2修改echarts字体为思源黑体-避免侵权-可以更换为任意字体统一管理
  • Linux 权限管理
  • API文档生成与测试工具推荐
  • 提示词工程实战指南:解锁AI创作的隐藏技巧与实例
  • AI驱动全流程基于PLUS-InVEST模型的生态系统服务多情景智能模拟与土地利用优化、论文写作
  • Python3: 函数式编程特性
  • 基于Spring Boot 电商书城平台系统设计与实现(源码+文档+部署讲解)
  • Day16(贪心算法)——LeetCode45.跳跃游戏II763.划分字母区间
  • 异步IO与Tortoise-ORM的数据库
  • Markdown转WPS office工具pandoc实践笔记
  • 从 Pretrain 到 Fine-tuning:大模型迁移学习的核心原理剖析
  • 《数据结构之美--二叉树oj题练习》
  • 数据结构每日一题day13(链表)★★★★★