-
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
http.get method() ignores query params when passing an URL as first argument #22162
Comments
http.get doesn't expect a whatwg url object, it expects an options argument similar to the output of |
The documentation says that the first argument can be an |
It is a very subtle thing... the documentation says Try the following: const http = require('http');
const assert = require('assert');
function parseJsonResp(next) {
return function(resp) {
var raw = '';
resp.on('data', function(chunk) {
raw += chunk;
});
resp.on('end', function() {
next(null, JSON.parse(raw));
});
}
};
const url = new URL('http://httpbin.org/get');
url.searchParams.set('foo', 'bar')
http.get(url, parseJsonResp(function(err, obj) {
assert(obj.args.foo === 'bar'); // It fails here
})); Key changes:
|
OK. Thanks! 👍. Shouldn't this be explicit on documentation? |
@gabriel-araujjo just to be clear, this issue can be closed now? Ah, missed your edit. Suggestions on how to make it more clear? |
I guess an example with that distinction is enough. |
The http URL has since been updated to support URL objects and properly handles the query string now so this can be closed. |
When passing an
URL
with query params as the first argument tohttp.get()
method, the query is ignored.The text was updated successfully, but these errors were encountered: