daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Jun 8th, 2017 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         /// <summary>
  2.         /// Lấy Token đăng nhập
  3.         /// </summary>
  4.         /// <param name="username"></param>
  5.         /// <param name="password"></param>
  6.         /// <returns></returns>
  7.         private static ApiKey GetToken(string username, string password)
  8.         {
  9.             using (var client = new HttpClient())
  10.             {
  11.                 client.BaseAddress = new Uri(Setting.DataBaseSetting.WebService917Location);
  12.                 client.DefaultRequestHeaders.Accept.Clear();
  13.                 client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  14.                 client.MaxResponseContentBufferSize = 2000005000;
  15.                 // HTTP POST
  16.                 //ApiToken input = new ApiToken { username = username, password = password };
  17.                 var values = new Dictionary<string, string>
  18.                 {
  19.                    { "username", username},
  20.                    { "password", Utilities.StringUtilities.CreateMD5(password) }
  21.                 };
  22.                 var content = new FormUrlEncodedContent(values);
  23.                 //var data = string.Format("username={0}&password={1}", username, password);
  24.                 HttpResponseMessage response = client.PostAsync("api/token/take", content).Result;
  25.                 if (response.IsSuccessStatusCode)
  26.                 {
  27.                     string result = response.Content.ReadAsStringAsync().Result;
  28.                     //string ss = response.Content.ReadAsAsync().Result;
  29.                     KQPhienLamViec plv = (KQPhienLamViec)JsonConvert.DeserializeObject<KQPhienLamViec>(result);
  30.                     //= response.Content.ReadAsAsync<KQPhienLamViec>().Result;
  31.                     if (plv.maKetQua == "200")
  32.                     {
  33.                         return plv.APIKey;
  34.                     }
  35.                 }
  36.                 return null;
  37.             }
  38.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top