当前位置: 首页> 教育> 锐评 > 重庆刮刮卡制作_828企业服务平台_合肥网络推广优化公司_腾讯朋友圈广告代理

重庆刮刮卡制作_828企业服务平台_合肥网络推广优化公司_腾讯朋友圈广告代理

时间:2025/7/11 19:59:29来源:https://blog.csdn.net/u013141712/article/details/147600147 浏览次数:0次
重庆刮刮卡制作_828企业服务平台_合肥网络推广优化公司_腾讯朋友圈广告代理
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%')}
}

关键字:重庆刮刮卡制作_828企业服务平台_合肥网络推广优化公司_腾讯朋友圈广告代理

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: