C
C
client242016-03-04 20:42:08
JavaScript
client24, 2016-03-04 20:42:08

How to make an https request?

var HttpsProxyAgent = require('https-proxy-agent');
    var request = require('request');
    var sslRootCAs = require('ssl-root-cas/latest')
    sslRootCAs.inject()


    var proxy = 'http://192.168.1.243:8888';
    var agent = new HttpsProxyAgent(proxy);
    request({
      uri: "https://vk.com",
      method: "POST",
      headers: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      agent: agent,
      timeout: 10000,
      followRedirect: true,
      maxRedirects: 10,
      body: "name=john"
    }, function(error, response, body) {
      console.log("Error" + error);
      console.log("Response: " + response);
      console.log("Body: " + body);
    });

I try to make such a request,
I get a response
ErrorError: unable to verify the first certificate
Response: undefined
Body: undefined

how to fix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Yandimirkin, 2016-03-07
@vlaad360

Why do you need an agent? and what are you trying to achieve?

const https = require('https');

var options = {
  hostname: 'vk.com',
  path: '/',
  method: 'POST'
};

var req = https.request(options, (res) => {
  console.log('statusCode: ', res.statusCode);
  console.log('headers: ', res.headers);

  res.on('data', (d) => {

  });
});
req.end();

req.on('error', (e) => {
  console.error(e);
});

6cfd58375a1a4836bdb2c81415b6ad6a.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question