http request 请求不到接口数据

import http from '@ohos.net.http';

export function doList() {
    const url = 'http://127.0.0.1:7001/api/users?currentPage=1&pageSize=100'
    const httpRequest= http.createHttp();
    const p =  httpRequest.request(url);
    p.then(res =>{
        console.log(JSON.stringify(res))
    }).catch(e =>{
        console.log(JSON.stringify(e))
    })
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

接口本地测试正常

 

config.json

  "deviceConfig": {
    "default": {
      "network": {
        "cleartextTraffic": true
      }
    }
  },
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
鸿蒙
接口
数据
2022-04-24 13:45:40
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Bessemer
2

可以参考案例进行接口调用。

https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-net-http-0000001168304341

let httpRequest= http.createHttp();
httpRequest.request("EXAMPLE_URL",
{
  method: 'GET',
  header: {
    'Content-Type': 'application/json'
  },
  readTimeout: 60000,
  connectTimeout: 60000
},(err, data) => {
  if (!err) {
    console.info('Result:' + data.result);
    console.info('code:' + data.responseCode);
    console.info('header:' + data.header);
  } else {
    console.info('error:' + err.data);
  }
});
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
分享
微博
QQ
微信
回复
2022-04-24 15:44:48
相关问题
HarmonyOS http get请求不到内容
1171浏览 • 1回复 待解决
HarmonyOS HTTP-post请求接收不到参数
1065浏览 • 1回复 待解决
websocket和http数据请求示例
1769浏览 • 1回复 待解决
鸿蒙应用开发请求不到数据
9271浏览 • 2回复 待解决
HarmonyOS http请求数据报错
1112浏览 • 1回复 待解决
使用http模块实现数据请求
2029浏览 • 1回复 待解决
HarmonyOS http请求的JSON数据定义问题
1161浏览 • 1回复 待解决
HarmonyOS POST请求,服务端拿不到数据
1580浏览 • 1回复 待解决
HarmonyOS @kit.NetworkKit http request错误
775浏览 • 1回复 待解决
关于http请求数据发送异常问题的咨询
1179浏览 • 1回复 待解决
HarmonyOS 接口请求数据处理
728浏览 • 1回复 待解决