网址https://mobileapp.mydomain.com/api/uuids?filter[where][uuid]=02644da038b37d7ba70b7ee1a92ba1d9
输出
[{"uuid":"02644da038b37d7ba70b7ee1a92ba1d9","date":"2017/10/05","time":"8:31:41","verified":false,"token":"null","id":"59d5bcb52f416812b0fc817a"}]
在下面的代码https.get
中,结果不是json和process.stdout.write(d)
?
如何以较少的进程以json
格式获得输出。
const https = require('https');
var URL = 'https://mobileapp.mydomain.com/api/uuids?filter[where][uuid]=02644da038b37d7ba70b7ee1a92ba1d9';
https.get(URL, (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
}).on('error', (e) => {
console.error('ERROR:',e);
});
更新输出
输出process.stdout.write(d);
:
ClientRequest {
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] },
_events:
{ response: { [Function: bound onceWrapper] listener: [Function] },
socket: { [Function: bound onceWrapper] listener: [Function: onSocket] },
error: [Function] },
_eventsCount: 3,
_maxListeners: undefined,
output: [ 'GET /api/uuids?filter[where][uuid]=02644da038b37d7ba70b7ee1a92ba1d9 HTTP/1.1\r\nHost: mobileapp.mydomain.com\r\nConnection: close\r\n\r\n' ],
outputEncodings: [ 'latin1' ],
outputCallbacks: [ [Function: bound onFinish] ],
outputSize: 128,
writable: false,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: null,
connection: null,
_header: 'GET /api/uuids?filter[where][uuid]=02644da038b37d7ba70b7ee1a92ba1d9 HTTP/1.1\r\nHost: mobileapp.mydomain.com\r\nConnection: close\r\n\r\n',
_onPendingData: [Function: noopPendingOutput],
agent:
Agent {
domain:
Domain {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
members: [] },
_events: { free: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: { path: null },
requests: {},
sockets: { 'mobileapp.mydomain.com:443:::::::::': [Array] },
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
_sessionCache: { map: {}, list: [] } },
socketPath: undefined,
timeout: undefined,
method: 'GET',
path: '/api/uuids?filter[where][uuid]=02644da038b37d7ba70b7ee1a92ba1d9',
_ended: false,
res: null,
aborted: undefined,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
[Symbol(outHeadersKey)]: { host: [ 'Host', 'mobileapp.mydomain.com' ] } }
> statusCode: 200
headers: { server: 'nginx/1.13.5',
date: 'Thu, 05 Oct 2017 12:43:58 GMT',
'content-type': 'application/json; charset=utf-8',
'content-length': '146',
connection: 'close',
vary: 'Accept-Encoding, Origin, Accept-Encoding',
'access-control-allow-credentials': 'true',
'x-xss-protection': '1; mode=block',
'x-frame-options': 'DENY',
'strict-transport-security': 'max-age=0; includeSubDomains, max-age=31536000',
'x-download-options': 'noopen',
'x-content-type-options': 'nosniff',
etag: 'W/"92-jcLXCzK/YpUyGdSTWS1c4YsxlvU"' }
[{"uuid":"02644da038b37d7ba70b7ee1a92ba1d9","date":"2017/10/05","time":"8:31:41","verified":false,"token":"null","id":"59d5bcb52f416812b0fc817a"}]>