react fetch request with content type x www form urlencoded

Solutions on MaxInterview for react fetch request with content type x www form urlencoded by the best coders in the world

showing results for - "react fetch request with content type x www form urlencoded"
Sofia
25 Mar 2018
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})
22
similar questions