using System; using System.Collections.Specialized; using System.IO; using System.Net; using System.Text; namespace HNWD.Pregrant.Common { public class clsWebService { private string webServerIP = string.Empty; private WebClient webClient = new WebClient(); public clsWebService(string webServerIP) { this.webServerIP = webServerIP; webClient.Credentials = CredentialCache.DefaultCredentials; webClient.Encoding = System.Text.Encoding.GetEncoding("UTF-8"); } public string WebServerIP { get { return this.webServerIP; } set { this.webServerIP = value; } } public string HttpServer { get { return "http://" + this.webServerIP + "/"; } } public string GetDataString(string subURL, string strPostData) { Byte[] bytes = Encoding.GetEncoding("UTF-8").GetBytes(strPostData.ToString()); webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); webClient.Headers.Add("ContentLength", strPostData.Length.ToString()); return Encoding.UTF8.GetString(webClient.UploadData(this.HttpServer + subURL, "POST", bytes)); } public string GetDataString(string subURL, NameValueCollection nameValueCollection) { webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); return Encoding.UTF8.GetString(webClient.UploadValues(this.HttpServer + subURL, "POST", nameValueCollection)); } public string GetDataString(string subURL) { return Encoding.UTF8.GetString(webClient.DownloadData(new System.Uri(this.HttpServer + subURL))); } public Boolean GetDataFile(string subURL, string FileName) { bool bRes = false; if (File.Exists(FileName)) { File.Delete(FileName); } webClient.DownloadFile(this.HttpServer + subURL, FileName); if (File.Exists(FileName)) { bRes = true; } return bRes; } } }