/// <summary> /// login /// </summary> /// <returns>nothing</returns> public async Task LoginAsync( ) { RequestPostData data = new RequestPostData() { id = this.Id, method = "authenticate", jsonrpc = "2.0" }; [email protected]("user", this.Username); [email protected]("password", Password); [email protected]("client", this.Id); HttpContent content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("WebUntis/jsonrpc.do?school=" + School, content); response.EnsureSuccessStatusCode( ); string str = await response.Content.ReadAsStringAsync( ); if (Debug) { Console.WriteLine(str); } SessionInformation = JsonConvert.DeserializeObject <SessionInformationTemporary>(str).result; Disconnected = false; ConnectEventHandler( ); }
private async Task <Answer <T> > _request <T>(string method, Dictionary <string, object> parameters, bool validateSession = true, string url = null) { if (validateSession) { await _validateSeassion( ); } if (url == null) { url = "WebUntis/jsonrpc.do?school=" + School; } RequestPostData data = new RequestPostData() { id = this.Id, method = method, jsonrpc = "2.0", @params = parameters }; if (Debug) { Console.WriteLine("request:" + JsonConvert.SerializeObject(data)); } HttpContent content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(url, content); response.EnsureSuccessStatusCode( ); if (Debug) { Console.WriteLine("answer:" + await response.Content.ReadAsStringAsync( ) + "\n"); } return(JsonConvert.DeserializeObject <Answer <T> >(await response.Content.ReadAsStringAsync( ))); }