public void Login() { try { var wc = new WebClient() { Credentials = Credentials }; string response = wc.DownloadString(API_URL + API_AUTH_URL); AccessToken = JObject.Parse(response)["token"].ToString(); OnUserLoginSuccess?.Invoke(this, new CnCNetEventUserLoginSuccess(response)); } catch (WebException ex) { try { OnUserLoginError?.Invoke(this, new CnCNetEventUserLoginError("Invalid username or password", ((HttpWebResponse)ex.Response).StatusCode)); } catch (Exception exx) { OnFatalError?.Invoke(this, new CnCNetEventFatalError(HttpStatusCode.BadGateway)); } } }
public void GetUsernames() { try { var wc = new WebClient(); wc.Headers.Add("Authorization", "Bearer:" + AccessToken); string response = wc.DownloadString(API_URL + API_ACCOUNT_URL); OnUsernamesSuccess?.Invoke(this, new CnCNetEventUsernamesSuccess(response)); } catch (WebException ex) { try { OnUserLoginError?.Invoke(this, new CnCNetEventUserLoginError(ex.Message, ((HttpWebResponse)ex.Response).StatusCode)); } catch (Exception exx) { OnFatalError?.Invoke(this, new CnCNetEventFatalError(HttpStatusCode.BadGateway)); } } }