Ich hab das so gelöst mit der Newtonsoft.JSON-Library:
~ Alex-Digital
C#-Quellcode
- public static SessionInfo CreateSession(string username, string password)
- {
- //WebRequest Setup
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://authserver.mojang.com/authenticate");
- request.UserAgent = "CustomLauncher/CustomLauncher/1.0";
- request.ContentType = "application/json";
- request.Method = "POST";
- //Payload
- string payload = JsonConvert.SerializeObject(new { agent = new { name = "Minecraft", version = 1 }, username = username, password = password });
- using (Stream stream = request.GetRequestStream())
- {
- stream.WriteString(Encoding.UTF8, payload);
- }
- //Response
- try
- {
- using (WebResponse response = request.GetResponse())
- using (Stream stream = response.GetResponseStream())
- using (StreamReader reader = new StreamReader(stream))
- {
- dynamic responseObject = JObject.Parse(reader.ReadToEnd());
- //Fehler finden und evtl. Exception werfen
- if (responseObject.accessToken == null)
- if (responseObject.errorMessage == null)
- throw new Exception("Response Empty");
- else
- throw new Exception("Response Error: " + responseObject.errorMessage);
- else if (responseObject.selectedProfile.id == null)
- throw new Exception("Response Error: Payload missing UUID and/or Username");
- String accessToken = responseObject.accessToken;
- String clientToken = responseObject.clientToken;
- String id = responseObject.selectedProfile.id;
- String name = responseObject.selectedProfile.name;
- return new SessionInfo(accessToken, clientToken, id, name);
- }
- }
- catch (WebException e)
- {
- System.Windows.Forms.MessageBox.Show(e.Status.ToString());
- return new SessionInfo(null, null, null, null);
- }
- }
~ Alex-Digital
~ Alex-Digital :D
if(!Internet.VBP.Get<User>("Alex-Digital").IsOnline) this.Close();