我在 API 調用后得到以下結果。我的節(jié)點版本是12.x {"type":"Buffer","data":[123,34,101,114,114,111,114,115,34,58,91,34,74,87,84,32,105,115,32,101,120,112,105,114,101,100,32,111,114,32,100,111,101,115,32,110,111,116,32,104,97,118,101,32,112,114,111,112,101,114,32,39,101,120,112,39,32,99,108,97,105,109,34,93,125,11]}請參閱下面的代碼片段:let postOptions = { host: 'vault.server', path: '/v1/auth/gcp/login', method: HTTPS.POST_REQUEST, headers: { 'Content-Type': 'application/json; charset=utf-8', 'X-Vault-Namespace': 'mynamespace' }, json: true, rpDefaults: { strictSSL: false } }; let requestPayLoad = { "role": this._vaultRole, "jwt": signedJWT }; console.log(JSON.stringify(requestPayLoad)); console.log(JSON.stringify(postOptions)); try { let result = await HTTPS.makeRequest(postOptions, JSON.stringify(requestPayLoad), HTTPS.POST_REQUEST); console.log('Response***************',JSON.stringify(result)); return result.auth.client_token; }請參閱下面的 http make 請求方法的代碼片段。return new Promise((resolve, reject) => { let rq = https.request(options, (res) => { let response; let chunks = []; res.on('data', (chunk) => { chunks.push(chunk); }); res.on('end', () => { response = Buffer.concat(chunks); return resolve(response); }); }); rq.on('error', (e) => { return reject({'statusCode': 500, 'success': false, 'error': e.toString()}); }); if (type === 'POST') { rq.write(data); } rq.end(); });請幫我解決這個問題
如何解決“NodeJS API 調用響應是無法解析的對象”?
明月笑刀無情
2023-09-21 16:58:34