简体   繁体   中英

How to fix server connection using https client with basic auth and tls pfx certificate?

I am trying connect third part server with basic auth and pfx tls certificate using node express platform. I am not sure; Where do I need to set basic auth, cert file and header params?

For get operation call from remote server, I have tried to use, https client and tls tool. Request requires ; header = basic auth,schemaVersion, id, applicationName

In addition to sending the basic auth credentials, send the following in the HTTP Header: Content-Type: application/json Accept: application/json

and also request require one additional parameter ie categories

onst https = require('https');
    const options = {
          hostname: 'https://yadda/cards/getAssets',
          headers: {
            Authorization: 'Basic ' + new Buffer(username + ':' + passw).toString('base64'),
            schemaVersion: '2.0.0',
            id: '0000000',
            applicationName: 'yadda',
            Accept: 'application/json',
            'Content-Type': 'application/json',
          },

          pfx: fs.readFileSync('/somefile.cert.pfx'),
          passphrase: 'passphrase',
          categories: 'food',
        };

       https
          .get(options, (response: any) => {
            response.on('data', (d: any) => {
              console.log(`BODY: `, d);
            });
          })
          .on('error', (e: any) => {
            console.error('Error: ', e);
          });

// With Tls tool, I tried as;
var fs = require('fs');
    var socket = tls.connect(options, () => {
      console.log('client connected');
      process.stdin.pipe(socket);
      process.stdin.resume();
    });

I would like to get connected with remote server and receive data in response; instead I am getting following error;

ERROR] Error:  { Error: getaddrinfo ENOTFOUND https://yadd/cards/getAssets:443
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'https://yadda/cards/getAssets', 

A hostname (like www.example.com ) is expected here, not a URL. The string you gave will be used as hostname and a DNS lookup will fail:

  ERROR] Error: { Error: getaddrinfo ENOTFOUND https://yadd/cards/getAssets:443 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM