public override void PaintPrinter() { if (this.GetCurrentPage() == 1) { TemplateTextObject text; Font font; for (int i = 0; i < config.Lists.Count; i++) { text = config.Lists[i]; if (text.ImgPath.Length > 0) { Image _tmpImage = null; if (text.ImgPath.StartsWith("http")) { try { // Open a connection System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(text.ImgPath); _HttpWebRequest.AllowWriteStreamBuffering = true; // set timeout for 20 seconds (Optional) _HttpWebRequest.Timeout = 20000; // Request response: System.Net.WebResponse _WebResponse = _HttpWebRequest.GetResponse(); // Open data stream: System.IO.Stream _WebStream = _WebResponse.GetResponseStream(); // convert webstream to image _tmpImage = Image.FromStream(_WebStream); // Cleanup _WebResponse.Close(); _WebResponse.Close(); } catch (Exception _Exception) { // Error Console.WriteLine("Exception caught in process: {0}", _Exception.ToString()); } } else { _tmpImage = Image.FromFile(text.ImgPath); } this.DrawImage(_tmpImage, new Point(text.Left, text.Top)); } else { font = new Font(text.FontName, text.FontSize); this.DrawStringHor(text.Content, font, new Point(text.Left, text.Top)); } } } }
private void Login(System.Net.IWebProxy proxy) { if (cookie == null) { //System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("https://www.secure.pixiv.net/login.php"); System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.pixiv.net/login.php"); req.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; req.Proxy = proxy; req.Timeout = 8000; req.Method = "POST"; //prevent 302 req.AllowAutoRedirect = false; //user & pass int index = rand.Next(0, user.Length); string data = "mode=login&pixiv_id=" + user[index] + "&pass="******"&skip=1"; byte[] buf = Encoding.UTF8.GetBytes(data); req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = buf.Length; System.IO.Stream str = req.GetRequestStream(); str.Write(buf, 0, buf.Length); str.Close(); System.Net.WebResponse rsp = req.GetResponse(); //HTTP 302然后返回实际地址 cookie = rsp.Headers.Get("Set-Cookie"); if (/*rsp.Headers.Get("Location") == null ||*/ cookie == null) { throw new Exception("自动登录失败"); } //Set-Cookie: PHPSESSID=3af0737dc5d8a27f5504a7b8fe427286; expires=Tue, 15-May-2012 10:05:39 GMT; path=/; domain=.pixiv.net int sessionIndex = cookie.LastIndexOf("PHPSESSID"); cookie = cookie.Substring(sessionIndex, cookie.IndexOf(';', sessionIndex) - sessionIndex); rsp.Close(); } }
/// <summary> /// Sendet die Abfrage zum Server /// </summary> /// <returns></returns> public String SendRequest() { // Parameter byte[] bytes = Encoding.UTF8.GetBytes(this.GetRequestCommand()); System.Net.WebRequest request = System.Net.WebRequest.Create(this.RequestAdress); request.Method = "POST"; request.ContentType = this.ContentType; request.ContentLength = bytes.Length; // Ausgangs Stream System.IO.Stream reqStr = request.GetRequestStream(); reqStr.Write(bytes, 0, bytes.Length); reqStr.Close(); reqStr.Flush(); // Antwort Stream System.Net.WebResponse response = request.GetResponse(); System.IO.Stream resStr = response.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(resStr); String ResponseString = reader.ReadToEnd(); reader.Close(); resStr.Close(); response.Close(); return(ResponseString); }
public System.Drawing.Image download() { // I coppied this section from http://forgetcode.com/CSharp/2052-Download-images-from-a-URL and tweeked it to my needs // The rest of this class is mine // **********************************************************HERE*********************************************************************************** System.Drawing.Image image = null; try { System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(m_URL); webRequest.AllowWriteStreamBuffering = true; webRequest.Timeout = 30000; System.Net.WebResponse webResponse = webRequest.GetResponse(); System.IO.Stream stream = webResponse.GetResponseStream(); image = System.Drawing.Image.FromStream(stream); webResponse.Close(); return(image); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("something went wrong with downloading the image. " + ex.Message); return(image); } // *********************************************************TO HERE************************************************************************* }
private Bitmap downloadMap(string url) { Bitmap mapBtm = null; try { // Open connection System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url); httpWebRequest.AllowWriteStreamBuffering = true; // timeout (20 seconds) httpWebRequest.Timeout = 20000; // Response: System.Net.WebResponse webResponse = httpWebRequest.GetResponse(); // Open data stream: System.IO.Stream webStream = webResponse.GetResponseStream(); // Create new bitmap from stream mapBtm = new Bitmap(webStream); // Close webStream.Close(); webResponse.Close(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); return(null); } return(mapBtm); }
private byte[] GetRemoteImage(string galleryPictureUrl) { if (galleryPictureUrl == null || galleryPictureUrl == "") { return(null); // No remote image to grab } // Get the image from the Url byte[] bytes; System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(galleryPictureUrl); webRequest.Timeout = 3000; // Set the timeout to 3 seconds. TODO: Make this a parameter System.Net.WebResponse webResponse = webRequest.GetResponse(); Stream stream = webResponse.GetResponseStream(); using (BinaryReader binaryReader = new BinaryReader(stream)) { bytes = binaryReader.ReadBytes(500000); binaryReader.Close(); } webResponse.Close(); return(bytes); }
public static Texture2D TextureFromURL(string url) { Texture2D image = null; try { System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); webRequest.AllowWriteStreamBuffering = true; webRequest.Timeout = 30000; System.Net.WebResponse webResponse = webRequest.GetResponse(); Stream stream = webResponse.GetResponseStream(); image = Texture2D.FromStream(game.GraphicsDevice, stream); webResponse.Close(); } catch { return(null); } return(image); }
public static String[] PegaEndereco(Page page, TextBox txtCEP, TextBox txtRua, TextBox txtBairro, TextBox txtCidade, TextBox txtUF, TextBox txtNumero) { txtRua.Text = ""; txtBairro.Text = ""; txtCidade.Text = ""; txtUF.Text = ""; String xml = ""; try { String url = String.Concat("http://cep.republicavirtual.com.br/web_cep.php?cep=", txtCEP.Text.Replace("-", ""), "&formato=xml"); System.Net.WebRequest request = System.Net.WebRequest.Create(url); System.Net.WebResponse response = request.GetResponse(); System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("ISO-8859-1")); xml = sr.ReadToEnd(); sr.Close(); sr.Dispose(); response.Close(); } catch { Alerta(null, page, "_errCep0", "CEP não encontrado.\\nVerfique os dados informados e tente novamente."); txtCEP.Focus(); return(null); } System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.LoadXml(xml); System.Xml.XmlNode root = doc.DocumentElement; System.Xml.XmlNode current = root.SelectSingleNode("/webservicecep/resultado"); if (current.InnerText == "0") { Alerta(null, page, "_errCep1", "CEP não encontrado.\\nVerfique os dados informados e tente novamente."); txtCEP.Focus(); return(null); } current = root.SelectSingleNode("/webservicecep/uf"); txtUF.Text = current.InnerText.ToUpper(); current = root.SelectSingleNode("/webservicecep/cidade"); txtCidade.Text = current.InnerText; current = root.SelectSingleNode("/webservicecep/bairro"); txtBairro.Text = current.InnerText; current = root.SelectSingleNode("/webservicecep/tipo_logradouro"); String tipoLogradouro = current.InnerText; current = root.SelectSingleNode("/webservicecep/logradouro"); String logradouro = current.InnerText; txtRua.Text = tipoLogradouro + " " + logradouro; txtNumero.Focus(); String[] arr = new String[] { txtUF.Text, txtCidade.Text, txtBairro.Text, txtRua.Text }; return(arr); }
public static Bitmap UrlToImage(string imageUrl) { Bitmap image = null; try { System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(imageUrl); webRequest.AllowWriteStreamBuffering = true; webRequest.Timeout = 30000; System.Net.WebResponse webResponse = webRequest.GetResponse(); System.IO.Stream stream = webResponse.GetResponseStream(); image = new Bitmap(stream); webResponse.Close(); } catch //(Exception ex)//Sécuriser!!!!!!!!!!!!!!!!!!!!!!!!!!!! { var base64Data = System.Text.RegularExpressions.Regex.Match(imageUrl, @"data:image/(?<type>.+?),(?<data>.+)").Groups["data"].Value; var binData = Convert.FromBase64String(base64Data); using (var stream = new MemoryStream(binData)) { image = new Bitmap(stream); } } return(image); }
/// <summary> /// Post 数据至接口端函数 /// </summary> /// <param name="postContent">提交内容</param> /// <param name="url">提交地址</param> /// <returns></returns> private string PostHttp(string postContent, string url) { string resultstr = string.Empty; System.Text.Encoding encode = System.Text.Encoding.GetEncoding("gb2312"); System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); req.Method = "POST"; req.ContentType = "text/xml"; req.Timeout = 1000000; Byte[] bytes = encode.GetBytes(postContent); req.ContentLength = bytes.Length; Stream sendStream = req.GetRequestStream(); sendStream.Write(bytes, 0, bytes.Length); sendStream.Close(); System.Net.WebResponse rep = req.GetResponse(); Stream getStream = rep.GetResponseStream(); using (StreamReader sr = new StreamReader(getStream, Encoding.UTF8)) { resultstr = sr.ReadToEnd(); sr.Close(); } getStream.Close(); rep.Close(); return(resultstr); }
// $G$ CSS-999 (-3) missing blank lines private Image downloadImageFromUrl(string i_ImageUrl) { Image image = null; try { System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(i_ImageUrl); webRequest.AllowWriteStreamBuffering = true; webRequest.Timeout = 30000; System.Net.WebResponse webResponse = webRequest.GetResponse(); System.IO.Stream stream = webResponse.GetResponseStream(); image = System.Drawing.Image.FromStream(stream); webResponse.Close(); } catch (Exception ex) { return(null); } return(image); }
public System.Drawing.Image processImagesUrl(string imageUrl) { System.Drawing.Image image = null; try { System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(imageUrl); webRequest.AllowWriteStreamBuffering = true; webRequest.Timeout = 30000; System.Net.WebResponse webResponse = webRequest.GetResponse(); System.IO.Stream stream = webResponse.GetResponseStream(); image = System.Drawing.Image.FromStream(stream); webResponse.Close(); } catch (Exception ex) { Logging.PutError("ERROR Download img", ex); return(null); } return(image); }
public string GetHttpData(string Url) { string sException = null; string sRslt = null; System.Net.WebResponse oWebRps = null; System.Net.WebRequest oWebRqst = System.Net.WebRequest.Create(Url); oWebRqst.Timeout = 50000; try { oWebRps = oWebRqst.GetResponse(); } catch (System.Net.WebException e) { sException = e.Message.ToString(); // EYResponse.Write(sException); } catch (Exception e) { sException = e.ToString(); // EYResponse.Write(sException); } finally { if (oWebRps != null) { System.IO.StreamReader oStreamRd = new System.IO.StreamReader(oWebRps.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8")); sRslt = oStreamRd.ReadToEnd(); oStreamRd.Close(); oWebRps.Close(); } } return(sRslt); }
public System.Drawing.Image ExportAttachments(string accountName, string projectName, string attachmentId, string attachmentName) { System.Drawing.Image image = null; try { HttpConfigurations oAppConfigurations = new HttpConfigurations(); oAppConfigurations.BaseUrl = _baseUrl; oAppConfigurations.UrlParams = string.Format("{0}/{1}/_apis/wit/attachments/{2}?download=true&api-version=5.0", accountName, projectName, attachmentId); oAppConfigurations.SecurityKey = _token; oAppConfigurations.ContentType = Constants.ContentTypeJson; oAppConfigurations.HttpMethod = Constants.Get; oAppConfigurations.AuthenticationScheme = AuthConfig.AuthType; HttpServices oHttpService = new HttpServices(oAppConfigurations); System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(oAppConfigurations.BaseUrl + "/" + oAppConfigurations.UrlParams); webRequest.AllowWriteStreamBuffering = true; webRequest.ContentType = "application/json"; webRequest.Headers.Add("Authorization", oAppConfigurations.AuthenticationScheme + " " + oAppConfigurations.SecurityKey); System.Net.WebResponse webResponse = webRequest.GetResponse(); System.IO.Stream stream = webResponse.GetResponseStream(); image = System.Drawing.Image.FromStream(stream); webResponse.Close(); } catch (Exception ex) { return(null); } return(image); }
/// <summary> /// Function pour télécharger une Image via une URL. /// </summary> /// <param name="_URL">URL address to download image</param> /// <returns>Image</returns> public Image DownloadImage(string _URL) { Image _tmpImage = null; try { // Open a connection System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(_URL); _HttpWebRequest.AllowWriteStreamBuffering = true; // set timeout for 20 seconds (Optional) _HttpWebRequest.Timeout = 20000; // Request response: System.Net.WebResponse _WebResponse = _HttpWebRequest.GetResponse(); // Open data stream: System.IO.Stream _WebStream = _WebResponse.GetResponseStream(); // convert webstream to image _tmpImage = Image.FromStream(_WebStream); // Cleanup _WebResponse.Close(); } catch (Exception _Exception) { // Error Console.WriteLine("Exception caught in process download image from url:", _Exception.ToString()); return(null); } return(_tmpImage); }
public Stream GetURLStream(string strURL) { System.Net.WebRequest objRequest; System.Net.WebResponse objResponse = null; Stream objStreamReceive; try { objRequest = System.Net.WebRequest.Create(strURL); objRequest.Timeout = 5000; objResponse = objRequest.GetResponse(); objStreamReceive = objResponse.GetResponseStream(); return(objStreamReceive); } catch (Exception excep) { Console.WriteLine(excep.Message); objResponse.Close(); return(null); } }
public System.Drawing.Image GetAvatarImage(SocketUser user) { System.Drawing.Image image = null; try { System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(user.GetAvatarUrl()); webRequest.AllowWriteStreamBuffering = true; webRequest.Timeout = 30000; System.Net.WebResponse webResponse = webRequest.GetResponse(); System.IO.Stream stream = webResponse.GetResponseStream(); image = System.Drawing.Image.FromStream(stream); webResponse.Close(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(null); } return(image); }
public string GetPage(string url, NameValueCollection headers) { try { string ret = string.Empty; System.Net.WebRequest myRequest = System.Net.WebRequest.Create(url); myRequest.PreAuthenticate = true; myRequest.Method = "GET"; if (headers != null) { myRequest.Headers.Add(headers); } System.Net.WebResponse myResponse = myRequest.GetResponse(); try { var stream = myResponse.GetResponseStream(); var streamreader = new System.IO.StreamReader(stream); ret = streamreader.ReadToEnd(); return(ret.Replace("\x00", "")); } finally { myResponse.Close(); } } catch (Exception ex) { throw new Exception("Could not get HTML from " + url + ": " + ex.Message, ex); } }
public void ShouldGetAnswers() { var expectedTitle = "My expected Answers"; var answers_controller = new AnswerController(); System.Net.WebRequest request = System.Net.WebRequest.Create("http://localhost:49852/api/questions"); System.Net.WebResponse response = request.GetResponse(); System.IO.Stream datastream = response.GetResponseStream(); StreamReader str = new StreamReader(datastream); string read_resp = str.ReadToEnd(); str.Close(); response.Close(); string[] split = read_resp.Split(','); var title = String.Empty; foreach (var te in split) { var fin_string = te.Replace("{", "").Replace("}", "").Replace("]", "").Replace("[", ""). Replace("\"\"", "").Replace("\"", ""); title += fin_string; } Assert.AreEqual(title, expectedTitle); }
public string GetResponse() { // Get the api response. string apiResponse = ""; try { System.Net.WebResponse response = request.GetResponse(); this.Status = ((System.Net.HttpWebResponse)response).StatusDescription; dataStream = response.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(dataStream); apiResponse = reader.ReadToEnd(); // Console.WriteLine("API Response : {0}", apiResponse); // Clean up the streams. reader.Close(); dataStream.Close(); response.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } return(apiResponse); }
public static System.Drawing.Image DownloadImageFromUrl(string imageUrl) { System.Drawing.Image image = null; try { System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(imageUrl); webRequest.AllowWriteStreamBuffering = true; webRequest.Timeout = 30000; System.Net.WebResponse webResponse = webRequest.GetResponse(); System.IO.Stream stream = webResponse.GetResponseStream(); image = System.Drawing.Image.FromStream(stream); webResponse.Close(); } catch (Exception ex) { Console.WriteLine("error 0x2"); } return(image); }
bool CheckForHFT() { bool success = false; try { System.Net.WebRequest request = System.Net.WebRequest.Create(m_gameServer.GetBaseHttpUrl()); request.Method = "POST"; string postData = "{\"cmd\":\"happyFunTimesPing\"}"; byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData); request.ContentType = "application/json"; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); System.Net.WebResponse response = request.GetResponse(); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); dataStream.Close(); response.Close(); success = responseFromServer.Contains("HappyFunTimes"); if (success) { Debug.Log("HappyFunTimes found"); } } catch (System.Exception) { Debug.Log("waiting for happyfuntimes..."); } return(success); }
/// <summary> /// 根据url获取文件的大小 /// </summary> /// <param name="url"></param> /// <returns></returns> public long Size(string url) { System.Net.WebRequest req = System.Net.HttpWebRequest.Create(url); req.Method = "HEAD"; System.Net.WebResponse resp = req.GetResponse(); resp.Close(); return(resp.ContentLength); }
private static void GETstringHead(string url, string bUri, ref Types[] types) { /* * Достает строку ответа на get-запрос */ try { System.Net.WebRequest reqGET = System.Net.WebRequest.Create(url); reqGET.Method = "HEAD"; reqGET.Timeout = 500; System.Net.WebResponse resp = reqGET.GetResponse(); bool repeat = false; foreach (Types type in types) { if (type.type == resp.ContentType) { //если такой тип уже есть, то добавляем в суммарный размер repeat = true; type.size += resp.ContentLength; //Console.WriteLine("Add type: " + resp.ContentType); } } if (!repeat) { //если тип не найден, то создаем новый элемент Array.Resize <Types>(ref types, types.Length + 1); types[types.Length - 1] = new Types(resp.ContentType, resp.ContentLength); //Console.WriteLine("Add type: " + resp.ContentType); } resp.Close(); //foreach (Types linkFrArr in types) Console.WriteLine(linkFrArr.type + linkFrArr.size); } catch (Exception e) { Console.WriteLine("В загрузке {1} ответа сервера произошло исключение: {0}", e.Message.ToString(), url); try { //Pass the filepath and filename to the StreamWriter Constructor StreamWriter sw = new StreamWriter("log.txt", true); //Write a line of text sw.WriteLine(bUri + " " + url); //Close the file sw.Close(); } catch (Exception e2) { Console.WriteLine("Exception: " + e2.Message); } finally { Console.WriteLine("Executing finally block."); } } }
/// <summary> /// 访问URL地址,返回值 /// </summary> /// <param name="url"></param> /// <param name="httpTimeout"></param> /// <param name="postEncoding"></param> /// <returns></returns> public static string CallWeb(string url, int httpTimeout, Encoding postEncoding) { string rStr = ""; System.Net.WebRequest req = null; System.Net.WebResponse resp = null; System.IO.Stream os = null; System.IO.StreamReader sr = null; try { //创建连接 req = System.Net.WebRequest.Create(url); req.ContentType = "application/x-www-form-urlencoded"; req.Method = "GET"; //时间 if (httpTimeout > 0) { req.Timeout = httpTimeout; } //读取返回结果 resp = req.GetResponse(); sr = new System.IO.StreamReader(resp.GetResponseStream(), postEncoding); rStr = sr.ReadToEnd(); int bodystart = rStr.IndexOf("<body>") + 6; //除去<body> int bodylenght = rStr.LastIndexOf("</body>") - bodystart; //除去</body> rStr = rStr.Substring(bodystart, bodylenght).Trim(); //除去空格 } catch { return(rStr); } finally { //关闭资源 if (os != null) { os.Dispose(); os.Close(); } if (sr != null) { sr.Dispose(); sr.Close(); } if (resp != null) { resp.Close(); } if (req != null) { req.Abort(); req = null; } } return(rStr); }
public static byte[] GetBytesFromUrl(Uri url) { System.Net.WebRequest webReq = System.Net.WebRequest.Create(url); webReq.Method = @"GET"; System.Net.WebResponse webResp = webReq.GetResponse(); System.IO.Stream stream = webResp.GetResponseStream(); System.IO.BinaryReader br = new System.IO.BinaryReader(stream); byte[] buffer = br.ReadBytes((int)webResp.ContentLength); webResp.Close(); return(buffer); }
/******************************/ /* Menu Events */ /******************************/ #region Menu Events #endregion /******************************/ /* Other Events */ /******************************/ #region Other Events #endregion /******************************/ /* Other Functions */ /******************************/ #region Other Functions /// <summary> /// CheckIfUpdateIsAvailable /// </summary> /// <returns></returns> private bool CheckIfUpdateIsAvailable() { try { string URL = Properties.Settings.Default.UpdateURL; System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URL); myRequest.Method = "GET"; System.Net.WebResponse myResponse = myRequest.GetResponse(); StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8); string result = sr.ReadToEnd(); System.Diagnostics.Debug.WriteLine(result); result = result.Replace('\n', ' '); sr.Close(); myResponse.Close(); System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); xmlDoc.LoadXml(result); System.Xml.XmlNodeList parentNode = xmlDoc.GetElementsByTagName("Version"); string remoteVersion = parentNode[0].InnerXml.ToString(); string remoteVersionAddition = ""; int countOfDots = System.Text.RegularExpressions.Regex.Matches(remoteVersion, "[.]").Count; if (countOfDots == 1) { remoteVersionAddition = ".0.0"; } else { remoteVersionAddition = ".0"; } Version sVersionToDownload = new Version(parentNode[0].InnerXml.ToString() + remoteVersionAddition); Version sCurrentVersion = new Version(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); var vResult = sVersionToDownload.CompareTo(sCurrentVersion); if (vResult > 0) { return(true); } else if (vResult < 0) { return(false); } else if (vResult == 0) { return(false); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } return(true); }
/// <summary> /// Do a HTTP request to get a webpage or text data from a server file /// </summary> /// <param name="url">URL of resource</param> /// <returns>Returns resource data if success, otherwise a WebException is raised</returns> private static string downloadString(string url) { System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); myRequest.Method = "GET"; System.Net.WebResponse myResponse = myRequest.GetResponse(); System.IO.StreamReader sr = new System.IO.StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8); string result = sr.ReadToEnd(); sr.Close(); myResponse.Close(); return(result); }
public static System.IO.Stream Get(string url, Bamboo.DataStructures.BufferPool bufferPool) { System.Net.WebRequest request = System.Net.HttpWebRequest.Create(url); request.Method = "GET"; System.Net.WebResponse response = request.GetResponse(); System.IO.Stream responseStream = new Bamboo.DataStructures.MemoryStream(bufferPool); Copy(response.GetResponseStream(), responseStream, (int)response.ContentLength, bufferPool); response.Close(); responseStream.Position = 0; return(responseStream); }
/// <summary> /// Function to download Image from website /// </summary> /// <param name="_URL">URL address to download image</param> /// <returns>Image</returns> public Image DownloadImage(string _URL) { Image _tmpImage = null; try { // Open a connection System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(_URL); _HttpWebRequest.AllowWriteStreamBuffering = true; // You can also specify additional header values like the user agent or the referer: (Optional) _HttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"; _HttpWebRequest.Referer = "http://www.google.com/"; // set timeout for 20 seconds (Optional) _HttpWebRequest.Timeout = 20000; // Request response: System.Net.WebResponse _WebResponse = _HttpWebRequest.GetResponse(); // Open data stream: System.IO.Stream _WebStream = _WebResponse.GetResponseStream(); // convert webstream to image _tmpImage = Image.FromStream(_WebStream); // Cleanup _WebResponse.Close(); _WebResponse.Close(); } catch (Exception _Exception) { // Error Console.WriteLine("Exception caught in process: {0}", _Exception.ToString()); return(null); } return(_tmpImage); }