如何使用 SuperAgent 进行 https 调用?

How to make https calls using SuperAgent?

我在 React Native Android 中使用 SuperAgent,这类似于 Node.js 环境。我正在尝试使用 https 协议调用我的 API。但是,只需调用

Req = SuperAgent
        .get(‘https://url...')
        .set('Accept','application/json')
        .end(function(err, res){some code})

returns 找不到资源的错误。我没能在官方文档中找到 https 调用指南。非常感谢您的帮助!

一个最简单的例子

var request = require('superagent');
 //an example for Get
request
    .get(example_url) //give the url
    .set('Cookie', 'hello') //setting cookie
    .set('user-agent', 'Android') //setting UserAgent
    .end(function(error,res){
      /* handle the Response(res) or Error (err) */
    }.bind(this)); //bind is basically used when we use this inside end for setState or any other scenario (basically use of this)

//Example for POST

与上面相同只是东西不是 GET 你需要将其声明为 POST 并随它一起发送数据

以及其他的使用可以参考下面SuperAgent的lib https://www.npmjs.com/package/superagent 要么 https://github.com/visionmedia/superagent