Skip to content

What am I doing wrong? #782

Discussion options

You must be logged in to vote

Issue is not node or undici related. Its a GitHub api requirement I was missing (you have to specify a user-agent):

'use strict'

import undici from 'undici'
import http from 'http'

undici.request(
  'https://api.github.com/zen',
  {
    headers: [
      'user-agent', 'undici'
    ]
  },
  (error, { statusCode, headers, body }) => {
    if (error) {
      console.error(error)
      process.exit(1)
    }

    console.log(`Staus: ${statusCode}`)
    console.log(`Status Message: ${http.STATUS_CODES[statusCode]}`)
    console.log('Headers', headers)
    const bufs = []
    body.on('data', buf => { bufs.push(buf) })
    body.on('end', () => {
      console.log(Buffer.concat(bufs).toString('ut…

Replies: 5 comments 13 replies

Comment options

You must be logged in to vote
2 replies
@ronag
Comment options

@Ethan-Arrowood
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
11 replies
@ronag
Comment options

@ronag
Comment options

@ronag
Comment options

@ronag
Comment options

@ronag
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Ethan-Arrowood
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants