Closed amrsa1 closed 4 years ago
@H1Gdev
application/x-www-form-urlencoded
sample is the following.
return frisby.post('https://example.com/token', {
body: qs.stringify({
'client_id': '1f3g3eff-ac',
'grant_type': 'password',
'username': D.email('myAccount'),
'password': D.password('myAccount'),
'client_secret': 'secret',
'redirect_uri': 'https://example.com/signin-callback'
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
})
.expect('status', 200);
application/x-www-form-urlencoded
sample is the following.return frisby.post('https://example.com/token', { body: qs.stringify({ 'client_id': '1f3g3eff-ac', 'grant_type': 'password', 'username': D.email('myAccount'), 'password': D.password('myAccount'), 'client_secret': 'secret', 'redirect_uri': 'https://example.com/signin-callback' }), headers: { 'Content-Type': 'application/x-www-form-urlencoded', } }) .expect('status', 200);
didnt work same response
i got it works like code below
beforeAll(()=> {
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
const urlencoded = new URLSearchParams();
urlencoded.append('client_id', 'sdsdsdf-b3d5-1c434ae452bb');
urlencoded.append('grant_type', 'password');
urlencoded.append("username", "acc@email.com");
urlencoded.append("password", "test");
urlencoded.append('client_secret', 'any');
const requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};
return frisby
.fetch("https://example/default/token", requestOptions)
.expect('status', 200)
Glad to see you got this working. 👍
After all, is it parameters value problem ?
The following values are different.
After all, is it parameters value problem ?
The following values are different.
- client_id
- username
- password
- client_secret
- redirect_uri
No not parameters im changing them randomly here for security purposes
Qs.stringfy didnt help in that case however it working on some other
Only way worked for me is the one i shared above
https://github.com/vlucas/frisby/issues/565#issue-635314848
'client_secret': 'secret',
https://github.com/vlucas/frisby/issues/565#issuecomment-641239204
urlencoded.append('client_secret', 'any');
As mentioned above, you were changing the value of parameters. I thought this is the cause.
Both do URL encoding, so I don't understand why URLSearchParams
solves this issue.
However, it is nice to solve this !!
'client_secret': 'secret',
urlencoded.append('client_secret', 'any');
As mentioned above, you were changing the value of parameters. I thought this is the cause.
Both do URL encoding, so I don't understand why
URLSearchParams
solves this issue.However, it is nice to solve this !!
actually you were right, your way is working as well
i just noticed the difference, i wrapped headers and body inside request maybe this was the issue
im getting unexpected response when im using post request with content type x-www-form-urlencoded i have tried to post the request with different ways but no luck, url and data are correct since same data is working fine with postman
expected response is 200 but im getting