Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- 'userName': 'test@gmail.com',
- 'password': 'Password!',
- 'grant_type': 'password'
- }
- var obj = {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
- },
- };
- fetch('https://example.com/login', obj)
- .then(function(res) {
- // Do stuff with result
- });
- var params = {
- userName: 'test@gmail.com',
- password: 'Password!',
- grant_type: 'password'
- };
- var formData = new FormData();
- for (var k in params) {
- formData.append(k, params[k]);
- }
- var request = {
- method: 'POST',
- headers: headers,
- body: formData
- };
- fetch(url, request);
- var details = {
- 'userName': 'test@gmail.com',
- 'password': 'Password!',
- 'grant_type': 'password'
- };
- var formBody = [];
- for (var property in details) {
- var encodedKey = encodeURIComponent(property);
- var encodedValue = encodeURIComponent(details[property]);
- formBody.push(encodedKey + "=" + encodedValue);
- }
- formBody = formBody.join("&");
- fetch('http://identity.azurewebsites.net' + '/token', {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/x-www-form-urlencoded'
- },
- body: formBody
- })
- var data = new URLSearchParams();
- data.append('userName', 'test@gmail.com');
- data.append('password', 'Password');
- data.append('grant_type', 'password');
- Object.prototype.serialize = function () {
- if (!this) return;
- var s = []
- for (var key in this) {
- if (this.hasOwnProperty(key)) {
- s.push(encodeURIComponent(key) + '=' + encodeURIComponent(this[key]))
- }
- }
- return s.join('&')
- }
- obj.serialize()
- var data = {
- a: 1,
- b: 2,
- c: true
- }
- fetch('/api_url', {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/x-www-form-urlencoded'
- },
- body: data.serialize() // see the usage here
- })
Add Comment
Please, Sign In to add comment