private async void button1_Click(object sender, EventArgs e) { var baseAddress = ConfigurationManager.AppSettings["baseUrl"]; using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("authorization", "Bearer nhb2ym7u7xrgwejwdb4k"); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); using (var content = new StringContent("{ \"login\": \"[email protected]\", \"password\": \"765312\"}", System.Text.Encoding.Default)) { using (var response = await httpClient.PostAsync("http://api.yclients.com/api/v1/auth", content)) { CrmAuth p = await response.Content.ReadAsAsync <CrmAuth>(); //string responseData = await response.Content.ReadAsStringAsync(); //richTextBox1.AppendText(responseData); //JObject json = JObject.Parse(responseData); //JsonSerializer serializer = new JsonSerializer(); /// CrmAuth p = (CrmAuth)serializer.Deserialize(new JTokenReader(json), typeof(CrmAuth)); pictureBox1.LoadAsync(p.avatar); richTextBox1.AppendText(Environment.NewLine + "user token " + p.user_token); } } } }
private async Task <CrmAuth> AuthorizeUser() { CrmAuth authInfo = await this.PostAction("auth", new StringContent("{ \"login\": \"" + WebApiConfig.CRM_LOGIN + "\", \"password\": \"" + WebApiConfig.CRM_PASSWORD + "\"}", System.Text.Encoding.Default)) .Content.ReadAsAsync <CrmAuth>(); return(authInfo); }