Ejemplo n.º 1
0
        private async Task <HttpResponseMessage> post(string _URI, JSONSerializable data, bool warnings)
        {
            string sContent = data.serialize();

            System.Diagnostics.Trace.TraceInformation(sContent);
            string URI = srvURI + _URI;

#if DEBUG && DISABLE_HTTP
            return(true);
#endif
            HttpContent         content  = new StringContent(sContent);
            HttpResponseMessage response = null;
            bool result = false;
            try
            {
                response = await client.PostAsync(URI, content);

                result = response.IsSuccessStatusCode;
                System.Diagnostics.Trace.TraceInformation(response.ToString());
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.TraceInformation(e.ToString());
            }
            if (_connected != result)
            {
                _connected = result;
                if (_connected)
                {
                    await processQueue();
                }
                connectionStateChanged?.Invoke(this, new EventArgs());
            }
            if (response?.StatusCode == System.Net.HttpStatusCode.BadRequest)
            {
                string srvMsg = await response.Content.ReadAsStringAsync();

                if (srvMsg == "Login expired")
                {
                    if (config.callsign.Length > 3 && config.password.Length > 5 && await login(config.callsign, config.password) == System.Net.HttpStatusCode.OK)
                    {
                        return(await post(_URI, data, warnings));
                    }
                }
                if (warnings)
                {
                    MessageBox.Show(await response.Content.ReadAsStringAsync(), "Bad request to server");
                }
            }
            return(response);
        }
Ejemplo n.º 2
0
 private async Task <HttpResponseMessage> post(string _URI, JSONSerializable data)
 {
     return(await post(_URI, data, true));
 }