private async Task ForwardToModBusProtocolAdapterAsync(byte[] message) { try { HttpContent content = new System.Net.Http.ByteArrayContent(message); content.Headers.ContentType = new MediaTypeHeaderValue(Constants.CONTENT_TYPE); content.Headers.ContentLength = message.Length; string requestUrl = IPHelper.GetAddress(); HttpResponseMessage response = await httpClient.PostAsync(requestUrl, content); Console.WriteLine("{0} - Forwarded msg to PA with status code '{1}'", DateTime.Now.ToString("hh:MM:ss.ffff"), response.StatusCode); } catch (WebException we) { Console.WriteLine("Web exception - {0}", we.Message); if (we.InnerException != null) { Console.WriteLine("Web inner exception - {0}", we.InnerException.Message); } } catch (Exception ex) { Console.WriteLine("Post exception - {0}", ex.Message); if (ex.InnerException != null) { Console.WriteLine("Post inner exception - {0}", ex.InnerException.Message); } } }
private void CreateHttpClient() { httpClient = new HttpClient(); requestUrl = IPHelper.GetLocalAdapterRequestUrl(config.ModBusContainer, config.ModBusPort, config.ModBusPath); }