public void Send(string report) { var webClient = new ExceptionReporterWebClient(_info.WebServiceTimeout) { Encoding = Encoding.UTF8 }; webClient.Headers.Add(HttpRequestHeader.ContentType, JSON); webClient.Headers.Add(HttpRequestHeader.Accept, JSON); webClient.UploadStringCompleted += OnUploadCompleted(webClient); using (var jsonStream = new MemoryStream()) { var sz = new DataContractJsonSerializer(typeof(ExceptionReportItem)); sz.WriteObject(jsonStream, new ExceptionReportItem { AppName = _info.AppName, AppVersion = _info.AppVersion, ExceptionMessage = _info.MainException.Message, ExceptionReport = report }); var jsonString = Encoding.UTF8.GetString(jsonStream.ToArray()); webClient.UploadStringAsync(new Uri(_info.WebServiceUrl), jsonString); } }
public bool Send(string report) { using (WebClient webClient = new ExceptionReporterWebClient(_info.WebReportUrlTimeout)) { webClient.Encoding = Encoding.UTF8; // https://stackoverflow.com/questions/5401501/how-to-post-data-to-specific-url-using-webclient-in-c-sharp // webClient.Headers.Add(HttpRequestHeader.ContentType, JSON); // webClient.Headers.Add(HttpRequestHeader.Accept, JSON); webClient.UploadStringCompleted += OnUploadCompleted(webClient); var reqparm = new System.Collections.Specialized.NameValueCollection { { "AppName", _info.AppName }, { "AppVersion", _info.AppVersion }, { "ExceptionMessage", _info.MainException.Message }, { "Report", report } }; byte[] responsebytes = webClient.UploadValues(_info.WebReportUrl, "POST", reqparm); string result = System.Text.Encoding.UTF8.GetString(responsebytes); // asume result text dont contains the word "error" its ok // maybe need check for http errors. if (!result.Contains("Error") && !result.Contains("error")) { return(true); } } return(false); }