-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: nodejs > http > get > Example KO #37907
Comments
Nice catch here! As docs, it is always desirable to provide a working example. (although the example is illustrative enough for me personally :))/ The entire world is turning into https, there is not so much Public APIs which provides http service without authentication required. Moreover, such service is not guaranteed to work in the future. Maybe we can spin up a local server to provide JSON service here? It could make things more controllable. Also, I think this is a good first issue here. Would you like to submit a PR? Thanks |
Hey there, Thanks for your response. I didn't had the time to put my hands into the repo's code, so I don't haev a PR to submit sadly :( The local server idea seems pretty good though ; or else simply switch the whole request to https0 Cheers |
Hi, If no one has taken this up yet, I'll be happy to push a quick fix. @Ayase-252 |
The example in question is to demostrate how to fetch a JSON response with "native" Node.js, therefore I prefer to host a very simple http server which outputs a JSON. Something like const svr = http.createServer((req, res) => {
res.writeHead(200, { "content-type": "application/json"})
res.end(`{
"data": "hello world"
}`)
})
svr.listen(8000) The Anyway, please feel free to take this 👍 |
In the JSON fetching example, http.get request is being sent to an http url that redirects to https. This causes the http.get request to fail. To avoid redirect errors, a local http server is set up that returns a json response. Fixes: nodejs#37907
In the JSON fetching example, http.get request is being sent to an http url that redirects to https. This causes the http.get request to fail. To avoid redirect errors, a local http server is set up that returns a json response. Fixes: #37907 PR-URL: #38036 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Nitzan Uziely <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
📗 API Reference Docs Problem
Location
Section of the site where the content exists
Affected URL(s):
Description
Concise explanation of the problem
Provided example doesn't work anymore, returns an error "Request failed. Status code: 301."
The provided url leads to http :
http.get('http://nodejs.org/dist/index.json', (res) => {
but said resource get automatically redirected to it's https twin.
In the example, anything other than 200 is thrown away
if (statusCode !== 200)
You need to set a new resource in http only (no redirection towards https) as the http module can't handle the https protocol ^^.
Cheers
submit a pull request.
The text was updated successfully, but these errors were encountered: