public void Run() { try { //init request HttpWebRequest httpWebRequest = HttpWebRequest.Create(this.url) as HttpWebRequest; httpWebRequest.Method = "POST"; httpWebRequest.ContentLength = this.data.Length; httpWebRequest.ContentType = "application/x-www-form-urlencoded"; using (StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream())) { sw.Write(this.data); } //get response HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse; using (StreamReader sr = new StreamReader(httpWebResponse.GetResponseStream())) { this.response = sr.ReadToEnd(); } } catch (Exception) { this.response = "{\"status\":\"failure\",\"message\":\"Http client error check connection\"}"; this.has_error = true; } if (HttpClientWrapper.getNotificationReceiver() != null) { LogServiceResponse formated_response = this.parent.unpackData(this.response); HttpClientWrapper.getNotificationReceiver().LoggingClientCompleted(formated_response, this.has_error); } }
public void Run() { try { using (WebClient client = new WebClient()) { this.response = client.DownloadString(this.url); } } catch (Exception) { this.response = "{\"status\":\"failure\",\"message\":\"Http client error check connection\"}"; this.has_error = true; } if (HttpClientWrapper.getNotificationReceiver() != null) { LogServiceResponse formated_response = this.parent.unpackData(this.response); HttpClientWrapper.getNotificationReceiver().LoggingClientCompleted(formated_response, this.has_error); } }