1var details = {
2 'userName': 'test@gmail.com',
3 'password': 'Password!',
4 'grant_type': 'password'
5};
6
7var formBody = [];
8for (var property in details) {
9 var encodedKey = encodeURIComponent(property);
10 var encodedValue = encodeURIComponent(details[property]);
11 formBody.push(encodedKey + "=" + encodedValue);
12}
13formBody = formBody.join("&");
14
15fetch('https://example.com/login', {
16 method: 'POST',
17 headers: {
18 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
19 },
20 body: formBody
21})