Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json.Linq;
- using System.Collections.Generic;
- using System.Net.Http;
- namespace app1
- {
- class Program
- {
- static void Main(string[] args)
- {
- var url = "https://api.dominio.com.br/login";
- var userName = "fulano@gmail.com";
- var password = "12345678";
- var token = GetToken(url, userName, password);
- }
- static string GetToken(string url, string userName, string password)
- {
- var pairs = new List<KeyValuePair<string, string>>
- {
- new KeyValuePair<string, string>( "username", userName ),
- new KeyValuePair<string, string> ( "password", password )
- };
- var content = new FormUrlEncodedContent(pairs);
- using (var client = new HttpClient())
- {
- var response = client.PostAsync(url, content).Result;
- JObject o = JObject.Parse(response.Content.ReadAsStringAsync().Result);
- return (string)o["token"];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement