请求接口地址:https://doc.quickapp.cn/features/system/fetch.html?h=fetch
第一步,安装包:
npm install iconv-lite
async onInit() { var prompt = require('@system.prompt'); { // 这是转换前的GBK var resultFetchOld = await fetch.fetch({ url: 'http://ip.ws.126.net/ipquery', responseType: 'text', method: 'GET', headers: { 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'cache-control': 'no-cache', 'pragma': 'no-cache',}, }); console.log('显示转换前的结果: ', resultFetchOld.data.data, '4秒后显示转换后的结果'); // 显示转换前的结果 setTimeout(function () { var htmlStr = '显示转换前的结果: ' + resultFetchOld.data.data + ',4秒后显示转换后的结果' prompt.showToast({ message: htmlStr }); }, 0); } var resultFetch = await fetch.fetch({ url: 'http://ip.ws.126.net/ipquery', responseType: 'arraybuffer', // responseType: 'text', method: 'GET', headers: { 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'cache-control': 'no-cache', 'pragma': 'no-cache', }, }); // console.log('resultFetch', resultFetch); // console.log('resultFetch.data.data', resultFetch.data.data) // console.log('resultFetch.data.data-stringify', JSON.stringify(resultFetch.data.data)); //这里是引入包 const Buffer = require('buffer').Buffer; // 这个包为 nodejs 自带,无需安装 const iconvLite = require('iconv-lite'); // let b1 = new Uint8Array(ipHtmlResult.data.data); //Buffer.from(b1,'hex')是把Uint8Array转化成Buffer类型数据 let htmlStr = iconvLite.decode(Buffer.from(resultFetch.data.data, 'hex'), 'gbk'); console.log('htmlStr', htmlStr); // 显示转换后的结果 setTimeout(function () { htmlStr = '显示转换后的结果: ' + htmlStr prompt.showToast({ message: htmlStr }); }, 4000); }
如果未开启 async 支持,请参考 https://doc.quickapp.cn/tutorial/framework/using-async.html?h=async
转自:http://Www.CnBlogs.Com/WebEnh/
如果想下次快速找到我,记得点下面的关注哦!
本博客Android APP 下载 |
![]() |
支持我们就给我们点打赏 |
![]() |
支付宝打赏 支付宝扫一扫二维码 |
![]() |
微信打赏 微信扫一扫二维码 |
![]() |
如果想下次快速找到我,记得点下面的关注哦!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2016-11-02 《AngularJS高级程序设计》学习笔记
2016-11-02 原 ng-include用法分析以及多标签页面的简单实现方式