Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. $http({
  2. method: 'POST',
  3. url: appConstant.webApiUrl + '/Token',
  4. data: userData,
  5. headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
  6. transformRequest: function (obj) {
  7. var str = [];
  8. for (var p in obj)
  9. str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
  10. return str.join("&");
  11. }
  12. }).success(function (data, status, headers, cfg) {
  13.  
  14. var obj = {
  15. method: 'POST',
  16. headers: {
  17. 'Accept': 'application/json',
  18. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  19. //'Origin': '',
  20. //'Host': 'api.producthunt.com'
  21. },
  22. body: JSON.stringify({
  23. 'userName': 'test@gmail.com',
  24. 'password': 'Password!',
  25. 'grant_type': 'password'
  26. })
  27. }
  28. fetch('http://identity.azurewebsites.net' + '/token', obj)
  29. .then(function(res) {
  30. console.log(res)
  31. return res.json();
  32. })
  33. .then(function(resJson) {
  34. console.log(resJson)
  35. return resJson;
  36. })
  37. }
  38. },
  39.  
  40. var str = [];
  41. var test = function(value){
  42. for (var p in value)
  43. str.push(encodeURIComponent(p) + "=" + encodeURIComponent(value[p]));
  44. return str.join("&");
  45. }
  46. test(value);
  47. var obj = {
  48. method: 'POST',
  49. headers: {
  50. 'Accept': 'application/json',
  51. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  52. },
  53. body:{data:str}
  54. }
  55. fetch('http://identity.azurewebsites.net' + '/token', obj)
  56. .then(function(res) {
  57. console.log(res)
  58. return res.json();
  59. })
  60. .then(function(resJson) {
  61. console.log(resJson)
  62. return resJson;
  63. })
  64.  
  65. var params = {
  66. userName: 'test@gmail.com',
  67. password: 'Password!',
  68. grant_type: 'password'
  69. };
  70.  
  71. var formData = new FormData();
  72.  
  73. for (var k in params) {
  74. formData.append(k, params[k]);
  75. }
  76.  
  77. var request = {
  78. method: 'POST',
  79. headers: headers,
  80. body: formData
  81. };
  82.  
  83. fetch(url, request);
  84.  
  85. var details = {
  86. 'userName': 'test@gmail.com',
  87. 'password': 'Password!',
  88. 'grant_type': 'password'
  89. };
  90.  
  91. var formBody = [];
  92. for (var property in details) {
  93. var encodedKey = encodeURIComponent(property);
  94. var encodedValue = encodeURIComponent(details[property]);
  95. formBody.push(encodedKey + "=" + encodedValue);
  96. }
  97. formBody = formBody.join("&");
  98.  
  99. fetch('http://identity.azurewebsites.net' + '/token', {
  100. method: 'POST',
  101. headers: {
  102. 'Accept': 'application/json',
  103. 'Content-Type': 'application/x-www-form-urlencoded'
  104. },
  105. body: formBody
  106. })
  107.  
  108. var data = new URLSearchParams();
  109. data.append('userName', 'test@gmail.com');
  110. data.append('password', 'Password');
  111. data.append('grant_type', 'password');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement