Skip to content

Instantly share code, notes, and snippets.

@denniswon
Created May 14, 2020 21:36
Show Gist options
  • Save denniswon/05136200704b92761ba9aeed210c1cea to your computer and use it in GitHub Desktop.
Save denniswon/05136200704b92761ba9aeed210c1cea to your computer and use it in GitHub Desktop.
get block by num axios
> const res = await axios.post('http://63.32.250.209:9500', '{"jsonrpc":"2.0","method":"hmy_getBlockByNumber","params":["0x31e182",true],"id":1}')
Thrown:
{ Error: Request failed with status code 415
at createError (/Users/dennis.won/go/src/github.com/harmony-one/harmony-dashboard-backend/node_modules/axios/lib/core/createError.js:16:15)
at settle (/Users/dennis.won/go/src/github.com/harmony-one/harmony-dashboard-backend/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/Users/dennis.won/go/src/github.com/harmony-one/harmony-dashboard-backend/node_modules/axios/lib/adapters/http.js:236:11)
at IncomingMessage.emit (events.js:203:15)
at IncomingMessage.EventEmitter.emit (domain.js:466:23)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
config:
{ url: 'http://63.32.250.209:9500',
method: 'post',
data:
'{"jsonrpc":"2.0","method":"hmy_getBlockByNumber","params":["0x31e182",true],"id":1}',
headers:
{ Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'axios/0.19.2',
'Content-Length': 83 },
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
adapter: [Function: httpAdapter],
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus] },
...
response:
{ status: 415,
statusText: 'Unsupported Media Type',
headers:
{ 'content-type': 'text/plain; charset=utf-8',
vary: 'Origin',
'x-content-type-options': 'nosniff',
date: 'Thu, 14 May 2020 21:34:14 GMT',
'content-length': '57',
connection: 'close' },
config:
{ url: 'http://63.32.250.209:9500',
method: 'post',
data:
'{"jsonrpc":"2.0","method":"hmy_getBlockByNumber","params":["0x31e182",true],"id":1}',
headers: [Object],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
adapter: [Function: httpAdapter],
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus] },
request:
ClientRequest {
domain: [Domain],
_events: [Object],
_eventsCount: 6,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Socket],
connection: [Socket],
_header:
'POST / HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/x-www-form-urlencoded\r\nUser-Agent: axios/0.19.2\r\nContent-Length: 83\r\nHost: 63.32.250.209:9500\r\nConnection: close\r\n\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
timeout: undefined,
method: 'POST',
insecureHTTPParser: undefined,
path: '/',
_ended: true,
res: [IncomingMessage],
aborted: undefined,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
_redirectable: [Writable],
[Symbol(isCorked)]: false,
[Symbol(outHeadersKey)]: [Object] },
data: 'invalid content type, only application/json is supported\n' },
isAxiosError: true,
toJSON: [Function] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment