发布请求未返回响应

时间:2019-09-17 12:49:35

标签: javascript node.js mean-stack

引用“ https://stripe.com/docs/connect/standard-accounts#token-request”以使用授权令牌发送发布请求,我能够成功检索授权令牌,但是当我创建POST请求时,它将返回给我请求正文,而不是我要寻找的参数。我需要:

{
  "token_type": "bearer",
  "stripe_publishable_key": "{PUBLISHABLE_KEY}",
  "scope": "read_write",
  "livemode": false,
  "stripe_user_id": "{ACCOUNT_ID}",
  "refresh_token": "{REFRESH_TOKEN}",
  "access_token": "{ACCESS_TOKEN}"
}

但是我得到了:

Request {
  _events: [Object: null prototype] { pipe: [Function] },
  _eventsCount: 1,
  _maxListeners: undefined,
  client_secret: '{blocked-OUT}',
  code: 'ac_FpKZWQuMK45h2ZZvOSrLNo30hZ2Knbg2',
  grant_type: 'authorization_code',
  uri:
   Url {
     protocol: 'https:',
     slashes: true,
     auth: null,
     host: 'connect.stripe.com',
     port: 443,
     hostname: 'connect.stripe.com',
     hash: null,
     search: null,
     query: null,
     pathname: '/oauth/token',
     path: '/oauth/token',
     href: 'https://connect.stripe.com/oauth/token' },
  method: 'POST',
  readable: true,
  writable: true,
  explicitMethod: true,
  _qs:
   Querystring {
     request: [Circular],
     lib:
      { formats: [Object], parse: [Function], stringify: [Function] },
     useQuerystring: undefined,
     parseOptions: {},
     stringifyOptions: {} },
  _auth:
   Auth {
     request: [Circular],
     hasAuth: false,
     sentAuth: false,
     bearerToken: null,
     user: null,
     pass: null },
  _oauth: OAuth { request: [Circular], params: null },
  _multipart:
   Multipart {
     request: [Circular],
     boundary: 'f0dfab2b-1296-466d-be00-1a52df65783f',
     chunked: false,
     body: null },
  _redirect:
   Redirect {
     request: [Circular],
     followRedirect: true,
     followRedirects: true,
     followAllRedirects: false,
     followOriginalHttpMethod: false,
     allowRedirect: [Function],
     maxRedirects: 10,
     redirects: [],
     redirectsFollowed: 0,
     removeRefererHeader: false },
  _tunnel:
   Tunnel {
     request: [Circular],
     proxyHeaderWhiteList:
      [ 'accept',
        'accept-charset',
        'accept-encoding',
        'accept-language',
        'accept-ranges',
        'cache-control',
        'content-encoding',
        'content-language',
        'content-location',
        'content-md5',
        'content-range',
        'content-type',
        'connection',
        'date',
        'expect',
        'max-forwards',
        'pragma',
        'referer',
        'te',
        'user-agent',
        'via' ],
     proxyHeaderExclusiveList: [] },
  headers: { host: 'connect.stripe.com' },
  setHeader: [Function],
  hasHeader: [Function],
  getHeader: [Function],
  removeHeader: [Function],
  localAddress: undefined,
  pool: {},
  dests: [],
  __isRequestRequest: true,
  proxy: null,
  tunnel: true,
  setHost: true,
  originalCookieHeader: undefined,
  _disableCookies: true,
  _jar: undefined,
  port: 443,
  host: 'connect.stripe.com',
  path: '/oauth/token',
  httpModule:
   { Agent: { [Function: Agent] super_: [Function] },
     globalAgent:
      Agent {
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        defaultPort: 443,
        protocol: 'https:',
        options: [Object],
        requests: {},
        sockets: {},
        freeSockets: {},
        keepAliveMsecs: 1000,
        keepAlive: false,
        maxSockets: Infinity,
        maxFreeSockets: 256,
        maxCachedSessions: 100,
        _sessionCache: [Object] },
     Server: { [Function: Server] super_: [Function] },
     createServer: [Function: createServer],
     get: [Function: get],
     request: [Function: request] },
  agentClass:
   { [Function: Agent]
     super_:
      { [Function: Agent] super_: [Function], defaultMaxSockets: Infinity } },
  agent:
   Agent {
     _events: [Object: null prototype] { free: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     defaultPort: 443,
     protocol: 'https:',
     options: { path: null },
     requests: {},
     sockets: {},
     freeSockets: {},
     keepAliveMsecs: 1000,
     keepAlive: false,
     maxSockets: Infinity,
     maxFreeSockets: 256,
     maxCachedSessions: 100,
     _sessionCache: { map: {}, list: [] } } }

这是我的代码的片段:

router.get('/', ensureAuthenticated, function(req, res, next) {
    header = req.param('code');
    //console.log(header);
    if (header) {
        var data = {
          'client_secret': '{blockedOUT}',
          'code': header,
          'grant_type': 'authorization_code'
        }
        var response = request.post('https://connect.stripe.com/oauth/token', data=data)
        console.log(response.text())
    }

    res.render('home', { title: 'Home' });
});

0 个答案:

没有答案