public void Send(ExceptionizerMessage message) { try { var requst = WebRequest.Create(this.configuration.ServerUri) as HttpWebRequest; if (requst == null) // log here return; requst.ContentType = "application/json"; requst.Accept = "application/json"; requst.KeepAlive = false; requst.Method = "POST"; PopulateRequestBody(requst, message); requst.BeginGetResponse(RequestCallback, requst); } catch (Exception) { //Log and return } }
private void PopulateRequestBody(HttpWebRequest requst, ExceptionizerMessage message) { var jsonSerializer = new JavaScriptSerializer(); string jsonSerializedMessage = jsonSerializer.Serialize(message); byte[] messagePayload = Encoding.UTF8.GetBytes(jsonSerializedMessage); requst.ContentLength = messagePayload.Length; using (var streamWriter = requst.GetRequestStream()) { streamWriter.Write(messagePayload, 0, messagePayload.Length); } }