-1

I am using SuperAgent in React Native Android which is similar to Node.js environment. I am trying to call my API using https protocol. However, by simply calling

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

returns error that res not found. I was not able to find https call guide in the official documentation. Really appreciate your help!

ZJL
  • 247
  • 5
  • 16
  • In the example they call a https url and its works. You got any errors? or no error and no res? https://github.com/visionmedia/superagent/blob/master/examples/simple-get.js – Marcos Bergamo Dec 01 '15 at 13:08
  • 1
    Thanks! I found error to be because of the server not https enabled. Thanks a lot! – ZJL Dec 02 '15 at 00:10

1 Answers1

1

A simplest example

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

same as above just the things are instead of GET u need to declare it as POST and send the data along with it

and the use of other things you can refer to the below lib of SuperAgent https://www.npmjs.com/package/superagent or https://github.com/visionmedia/superagent

Pramod Mg
  • 2,316
  • 1
  • 11
  • 14
  • Right, I just need to change http to https. Thanks for the bind(this) advice too. – ZJL Dec 02 '15 at 00:12