Last active
October 9, 2017 14:52
-
-
Save jatovar/6b4e53d883fb13c0c22f44fb18653cd1 to your computer and use it in GitHub Desktop.
Bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<string> GetKey() | |
{ | |
if (!IsConnected()) | |
throw new NotConnectedException(); | |
try | |
{ | |
using (HttpClient client = new HttpClient()) | |
{ | |
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaType)); | |
HttpContent content = new StringContent(string.Empty, Encoding.UTF8, MediaType); | |
var response = await client.PostAsync(LibroAzulWebService.LoginAddress, content); | |
string body = await response.Content.ReadAsStringAsync(); | |
var dto = JsonConvert.DeserializeObject<LibroAzul>(body); | |
if (dto.Success) | |
{ | |
Key = dto.Token; | |
return Key; | |
} | |
throw new Exception( | |
"Error en el backend al logear al libro azul" + | |
"\n Respuesta: " + JsonConvert.SerializeObject(dto) + | |
"\n HTTP Status: " + response.StatusCode); | |
} | |
} | |
catch (Exception e) | |
{ | |
throw e; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment