-
Describe the bugI'd like to convert a piece of code that logs into a website and retrieves some data from
Actual behavior
Expected behavior
Code to reproduceconst request = require('request-promise');
const got = require('got');
const tough = require('tough-cookie');
const FormData = require('form-data');
const loginWithRequest = async (username, password) => {
const jar = request.jar();
await request('https://www.unlimitedhorizon.co.uk', {jar: jar});
const response = await request.post('https://www.unlimitedhorizon.co.uk/webapp/signin?wicket:interface=:0:wrap:inner:signInPanel:signInForm::IFormSubmitListener::', {
simple: false, // Don't error on 302.
resolveWithFullResponse: true, // Include response headers.
jar: jar,
form: {
'username': username,
'password': password,
}
});
return (response.headers.location == 'dashboard/admin');
};
const loginWithGot = async (username, password) => {
const jar = new tough.CookieJar();
await got('https://www.unlimitedhorizon.co.uk', {cookieJar: jar});
const form = new FormData();
form.append('username', username);
form.append('password', password);
const response = await got.post('https://www.unlimitedhorizon.co.uk/webapp/signin?wicket:interface=:0:wrap:inner:signInPanel:signInForm::IFormSubmitListener::', {
cookieJar: jar,
body: form
});
// Not adapted to got yet but gets stuck before this point.
return (response.headers.location == 'dashboard/admin');
};
(async () => {
console.log('Request', await loginWithRequest(process.argv[2], process.argv[3]));
console.log('Got', await loginWithGot(process.argv[2], process.argv[3]))
})(); Checklist
|
Beta Was this translation helpful? Give feedback.
Replies: 13 comments 1 reply
-
If you set a timeout, the request times out. Can you try the npm install "sindresorhus/got#62305d77d3428b5c714d21b4bbee68cc75b5f787" |
Beta Was this translation helpful? Give feedback.
-
$ npm install "sindresorhus/got#62305d77d3428b5c714d21b4bbee68cc75b5f787"
[...]
> got@11.8.0 build
> del-cli dist && tsc
test/stream.ts:490:35 - error TS2769: No overload matches this call.
The last overload gave the following error.
Type 'Readable' is not assignable to type 'string | Readable | Buffer | undefined'.
Type 'Readable' is missing the following properties from type 'Readable': readableEncoding, readableEnded, readableObjectMode, pipe, and 8 more.
490 const response = await got.post({body});
~~~~
source/core/options.ts:1058:6
1058 get body(): string | Buffer | Readable | undefined {
~~~~
The expected type comes from property 'body' which is declared here on type 'OptionsInit'
source/types.ts:171:2
171 (options: OptionsInit): CancelableRequest | Request;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The last overload is declared here.
Found 1 error.
error Command failed with exit code 1. |
Beta Was this translation helpful? Give feedback.
-
In that case try cloning the repo and builiding it from there.
|
Beta Was this translation helpful? Give feedback.
-
@szmarczak this gives me the same error, even when building the commit you referenced. The same error can be seen in the builds on GitHub. |
Beta Was this translation helpful? Give feedback.
-
Managed to install got from HEAD with the latest commit and it still hangs when running this sample. A timeout can be set but that doesn't resolve the issue of request working on got not. |
Beta Was this translation helpful? Give feedback.
-
It's very likely that the issue is with |
Beta Was this translation helpful? Give feedback.
-
Looks like a Passing it to |
Beta Was this translation helpful? Give feedback.
-
Thank you for looking into this, appreciate it! This does seem to get one step closer but the |
Beta Was this translation helpful? Give feedback.
-
...
followRedirect: false,
... |
Beta Was this translation helpful? Give feedback.
-
Thank you. Everything is working as expected now, unfortunately when passing the correct credentials request is able to login, and got isn't (with
I realise you won't be able to help me diagnose that part but could you describe how to pass it as a string like you mentioned earlier?
|
Beta Was this translation helpful? Give feedback.
-
Simply pass a
You can use Wireshark or any other tool to debug this. |
Beta Was this translation helpful? Give feedback.
-
Note that in the |
Beta Was this translation helpful? Give feedback.
Note that in the
request
example you're usingapplication/x-www-form-urlencoded
but in the Got example you're usingmultipart/form-data
. Got accepts the first as well, using theform
option.