public static async Task VoteAsync(string host, int port, CookieCollection cookieCollection, Guid electionId, BigInteger[] encryptedVector) { var data = Encoding.UTF8.GetBytes(string.Format("electionId={0}&vote={1}", HttpUtility.UrlEncode(electionId.ToString()), HttpUtility.UrlEncode(encryptedVector.Select(integer => integer.ToString()).ToArray().ToJsonString()))); var uri = new Uri(string.Format("http://{0}:{1}/vote", host, port)); var httpResult = await AsyncHttpClient.DoRequestAsync(uri, WebRequestMethods.Http.Post, null, cookieCollection, data); if (httpResult.StatusCode != HttpStatusCode.OK) { throw new ServiceException(ExitCode.MUMBLE, string.Format("Failed to process VoteAsync: {0}", httpResult.StatusCode)); } }
public static async Task <CookieCollection> RegUserAsync(string host, int port, string login, string pass, string publicMessage = null, string privateNotes = null) { var data = Encoding.UTF8.GetBytes(string.Format("login={0}&pass={1}&publicMessage={2}&privateNotes={3}", HttpUtility.UrlEncode(login), HttpUtility.UrlEncode(pass), HttpUtility.UrlEncode(publicMessage), HttpUtility.UrlEncode(privateNotes))); var uri = new Uri(string.Format("http://{0}:{1}/register", host, port)); var httpResult = await AsyncHttpClient.DoRequestAsync(uri, WebRequestMethods.Http.Post, null, null, data); if (httpResult.StatusCode != HttpStatusCode.OK) { throw new ServiceException(ExitCode.MUMBLE, string.Format("Failed to process RegUserAsync: http-status {0}", httpResult.StatusCode)); } return(httpResult.cookieCollection); }
public static async Task <Election> NominateAsync(string host, int port, CookieCollection cookieCollection, Guid electionId) { var data = Encoding.UTF8.GetBytes(string.Format("electionId={0}", HttpUtility.UrlEncode(electionId.ToString()))); var uri = new Uri(string.Format("http://{0}:{1}/nominate", host, port)); var httpResult = await AsyncHttpClient.DoRequestAsync(uri, WebRequestMethods.Http.Post, null, cookieCollection, data); if (httpResult.StatusCode != HttpStatusCode.OK) { throw new ServiceException(ExitCode.MUMBLE, string.Format("Failed to process NominateAsync: {0}", httpResult.StatusCode)); } try { return(JsonHelper.ParseJson <Election>(httpResult.ResponseBytes)); } catch (Exception e) { throw new ServiceException(ExitCode.MUMBLE, "Failed to parse 'nominate' response (expected PrivateKey)\n" + e); } }