///<summary>Confirm a login. Throws an exception if it fails</summary> public void Confirm() { if (CurrentState != State.NEEDS_CONFIRMATION) { // Shouldn't be here throw new EliteDangerousCompanionAppIllegalStateException("Service in incorrect state to confirm login (" + CurrentState + ")"); } string code = CompanionAppCredentials.Instance().code; HttpWebRequest request = GetRequest(BASE_URL + CONFIRM_URL); request.ContentType = "application/x-www-form-urlencoded"; request.Method = "POST"; string encodedCode = WebUtility.UrlEncode(code); byte[] data = Encoding.UTF8.GetBytes("code=" + encodedCode); request.ContentLength = data.Length; using (Stream dataStream = request.GetRequestStream()) { dataStream.Write(data, 0, data.Length); } using (HttpWebResponse response = GetResponse(request)) { if (response == null) { throw new EliteDangerousCompanionAppException("Failed to contact API server"); } foreach (string key in response.Headers.AllKeys) { logger.log(key + " ==> " + response.Headers[key]); } //logger.log(response.StatusCode.ToString()); if (response.StatusCode == HttpStatusCode.Found && response.Headers["Location"] == ROOT_URL) { CurrentState = State.READY; } else if (response.StatusCode == HttpStatusCode.Found && response.Headers["Location"] == LOGIN_URL) { CurrentState = State.NEEDS_LOGIN; throw new EliteDangerousCompanionAppAuthenticationException("Confirmation code incorrect or expired"); } else if (response.StatusCode == HttpStatusCode.OK) { //CurrentState = State.NEEDS_LOGIN; throw new EliteDangerousCompanionAppAuthenticationException("Confirmation code incorrect"); } } }