LenovoUser lenovoUser = null;
string url = LenovoPrefix + "user/login_new";
HttpClient httpClient = new HttpClient();
List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>>();
paramList.Add(new KeyValuePair<string, string>("loginType", loginType));
paramList.Add(new KeyValuePair<string, string>("loginkey", loginkey));
paramList.Add(new KeyValuePair<string, string>("password", password));
try
{
var response = httpClient.PostAsync(new Uri(url), new FormUrlEncodedContent(paramList)).Result;
string result = response.Content.ReadAsStringAsync().Result;
lenovoUser = JsonHelper.JsonToEntity<LenovoUser>(result);
}
catch (Exception ex)
{
PlatFormHelper.Mvc.PFPageHelper.LogException("GetLenovoSessionID", ex);
}
return lenovoUser;
Json
string start_dttm = _pSDeptService.GetMaxLastupddt().ToString("yyyy-MM-dd HH:mm:ss");
string end_dttm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string url = PS_Url + "C_SERV_DEPT_POST.v1/";
string json = "{\"c_token_key\":\"" + c_token_key + "\",\"c_token_value\":\"" + c_token_value + "\",\"start_dttm\":\"" + start_dttm + "\",\"end_dttm\":\"" + end_dttm + "\"}";
HttpClient httpClient = new HttpClient();
HttpContent httpContent = new StringContent(json);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = httpClient.PostAsync(new Uri(url), httpContent).Result;
string result = response.Content.ReadAsStringAsync().Result;
Basic Auth
string url = $"https://{LoginInfo.hostIp}/oauth2/token";
if (url.StartsWith("https"))
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
}
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{LoginInfo.userName}:{LoginInfo.password}")));
HttpContent httpContent = new StringContent("grant_type=client_credentials", Encoding.UTF8, "application/x-www-form-urlencoded");
var response = httpClient.PostAsync(new Uri(url), httpContent).Result;
string result = response.Content.ReadAsStringAsync().Result;
var tokenResultModel = Newtonsoft.Json.JsonConvert.DeserializeObject<TokenResultModel>(result);
this.tokenId = tokenResultModel.access_token;
}