private bool SendCords(Api_Update data) { if (string.IsNullOrEmpty(apiurl)) return false; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(apiurl); httpWebRequest.Method = "POST"; httpWebRequest.ContentType = "application/json"; // your content type (change accordingly) // Send HttpContent HttpWebResponse response; try { using (System.IO.Stream s = httpWebRequest.GetRequestStream()) { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(s)) sw.Write(JsonConvert.SerializeObject(data)); } // Get Response response = (HttpWebResponse)httpWebRequest.GetResponse(); } catch { return false; } return (response.StatusCode == HttpStatusCode.OK); }
private void UpdateCords() { PlayerPosition playerpos = new PlayerPosition(); while (getdata) { Player player = playerpos.GetPlayerData(); if (transmit) { Api_Update data = new Api_Update(); txt_Api_Key.Dispatcher.Invoke(new Action(() => data.Api_Key = txt_Api_Key.Text)); data.Player.Name = player.Info.Name; data.Player.Commander = player.Info.Commander; data.Player.Profession = player.Info.Profession; data.Location.World_id = player.Location.World_id; data.Location.Map_id = player.Location.Map_id; data.Location.X = player.Location.X; data.Location.Y = player.Location.Y; data.Location.Z = player.Location.Z; if (!SendCords(data)) { lbl_Msg.Dispatcher.Invoke(new Action(() => lbl_Msg.Content = "There was an error sending the data")); } } lbl_debug.Dispatcher.Invoke(new Action(() => lbl_debug.Content = player.Location.World_id + ", " + player.Location.Map_id + ", X:" + player.Location.X + ", Y:" + player.Location.Y + ", Z:" + player.Location.Z)); Thread.Sleep(pollrate); } }