当前位置:   article > 正文

关于鸿蒙网络请求的问题_鸿蒙 http.requestmethod.post请求无数据

鸿蒙 http.requestmethod.post请求无数据

在这里插入图片描述
https://developer.huawei.com/consumer/cn/forum/topic/0204136145853212268?fid=0102683795438680754
在这里插入图片描述
鸿蒙OS 代码

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

export const httpUtils = (url: string, data: any) => {


  return new Promise((resolve, reject) => {

    let httpRequest = http.createHttp();
    let options = {
      method: data.method,
      extraData: {},


    }
    if (data.method == 'POST') {
      options.extraData = data.data || {}
    }
    console.log(options.method);
    httpRequest.request(url, options, (err, data) => {
      if (!err) {
        // data.result为HTTP响应内容,可根据业务需要进行解析
        console.info('Result:' + JSON.stringify(data));
        resolve(data)
        console.info('code:' + JSON.stringify(data.responseCode));
        // data.header为HTTP响应头,可根据业务需要进行解析
        console.info('header:' + JSON.stringify(data.header));
        console.info('cookies:' + JSON.stringify(data.cookies)); // 8+
      } else {
        console.info('error:' + JSON.stringify(err));
        reject(err)
        // 取消订阅HTTP响应头事件

        // 当该请求使用完毕时,调用destroy方法主动销毁

      }

    })

  })

}
 let data = {
      method: 'GET',

    }
    let testUrl = "http://192.168.31.74:8080/qiniu/list"

    const res = await httpUtils(testUrl, data);

    console.log("网络请求的数据" + JSON.stringify(res))
```![在这里插入图片描述](https://img-blog.csdnimg.cn/87171389c62f48ef99ff8dbcbb7ad6b3.png)


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/304189
推荐阅读
相关标签
  

闽ICP备14008679号