Advertisement
Guest User

Untitled

a guest
Jan 13th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. using Newtonsoft.Json.Linq;
  2. using System.Collections.Generic;
  3. using System.Net.Http;
  4.  
  5. namespace app1
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var url = "https://api.dominio.com.br/login";
  12. var userName = "fulano@gmail.com";
  13. var password = "12345678";
  14.  
  15. var token = GetToken(url, userName, password);
  16. }
  17.  
  18. static string GetToken(string url, string userName, string password)
  19. {
  20. var pairs = new List<KeyValuePair<string, string>>
  21. {
  22. new KeyValuePair<string, string>( "username", userName ),
  23. new KeyValuePair<string, string> ( "password", password )
  24. };
  25. var content = new FormUrlEncodedContent(pairs);
  26.  
  27. using (var client = new HttpClient())
  28. {
  29. var response = client.PostAsync(url, content).Result;
  30. JObject o = JObject.Parse(response.Content.ReadAsStringAsync().Result);
  31. return (string)o["token"];
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement