有没有办法从节点中的HTTPS请求获取会话ID?

时间:2017-06-22 01:08:11

标签: javascript session https

我无法弄清楚如何。我发了一个HTTPS get请求,但我得到了一长串信息,但没有SessionId

这是我在node.js中编写的代码。我已经用假的API替换了我的API,但其他的东西是相同的。

 var http = require('http');
//var port = process.env.PORT || 1337;
var https = require('https')
var readline = require('readline');
var url = require('url')
var request = require('request')

var body = ""

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

var options = {
    url: "https://SOMEAPI.com/us/oauth/v2/authorize?SOMEPATH",
    host: "SOMEAPI.com"
}

var cookie = https.get(options, (response) => {
    response.on(('data'), (chunk) => {
        body += chunk
    })
    response.on('end', () => {
        //printSession(response)
        //console.log(response)
    })
})

console.log(cookie)

这是我的控制台输出:

Debugger listening on [::]:5858
ClientRequest {
  domain: null,
  _events:
   { response: { [Function: g] listener: [Function] },
     socket: { [Function: g] listener: [Function: onSocket] } },
  _eventsCount: 2,
  _maxListeners: undefined,
  output: [ 'GET / HTTP/1.1\r\nHost: [https://SOMEAPI.com]\r\nConnect
ion: close\r\n\r\n' ],
  outputEncodings: [ 'latin1' ],
  outputCallbacks: [ [Function: finish] ],
  outputSize: 77,
  writable: true,
  _last: true,
  upgrading: false,
  chunkedEncoding: false,
  shouldKeepAlive: false,
  useChunkedEncodingByDefault: false,
  sendDate: false,
  _removedHeader: {},
  _contentLength: 0,
  _hasBody: true,
  _trailer: '',
  finished: true,
  _headerSent: true,
  socket: null,
  connection: null,
  _header: 'GET / HTTP/1.1\r\nHost: [https://SOMEAPI.com]\r\nConnecti
on: close\r\n\r\n',
  _headers: { host: '[https://SOMEAPI.com]' },
  _headerNames: { host: 'Host' },
  _onPendingData: null,
  agent:
   Agent {
     domain: null,
     _events: { free: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     defaultPort: 443,
     protocol: 'https:',
     options: { path: null },
     requests: {},
     sockets: { 'https://SOMEAPI.com:443::::::::[https': [Object] },
     freeSockets: {},
     keepAliveMsecs: 1000,
     keepAlive: false,
     maxSockets: Infinity,
     maxFreeSockets: 256,
     maxCachedSessions: 100,
     _sessionCache: { map: {}, list: [] } },
  socketPath: undefined,
  timeout: undefined,
  method: 'GET',
  path: '/',
  _ended: false }
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOTFOUND https://SOMEAPI.com https://SOMEAPI.com:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
Press any key to continue...

编辑:这就是我现在的情况:

Debugger listening on [::]:5858
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server</faultcode>
            <faultstring>Policy Falsified</faultstring>
            <faultactor>https://SOMEAPI.com/</faultactor>
            <detail>
                <l7:policyResult
                    status="Service Not Found.  The request may have been sent t
o an invalid URL, or intended for an unsupported operation." xmlns:l7="http://ww
w.layer7tech.com/ws/policy/fault"/>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server</faultcode>
            <faultstring>Policy Falsified</faultstring>
            <faultactor>https://SOMEAPI.com/</faultactor>
            <detail>
                <l7:policyResult
                    status="Service Not Found.  The request may have been sent t
o an invalid URL, or intended for an unsupported operation." xmlns:l7="http://ww
w.layer7tech.com/ws/policy/fault"/>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

我相信这可能是重要的标题信息:

REQUEST
GET https://SOMEAPI.com/us/oauth/v2/authorize?SOMEPATH HTTP/1.1
Accept: text/html, application/xhtml+xml, application/xml
Host: SOMEAPI.com
Connection: Keep-Alive

0 个答案:

没有答案