public static IBitmap DownloadImage(XmlNode output) { if (output.Attributes["file"] != null) { try { FileInfo fi = new FileInfo(output.Attributes["file"].Value); if (fi.Exists) { return(Current.Engine.CreateBitmap(fi.FullName)); } } catch (Exception ex) { LastErrorMessage = ex.Message; throw ex; } } if (output.Attributes["url"] != null) { return(DownloadImage( output.Attributes["url"].Value, ProxySettings.Proxy(output.Attributes["url"].Value), WebCredentials.FromXmlNode(output.SelectSingleNode("credentials")))); } return(null); }
public static IBitmap DownloadImage(string imageUrl, string usr, string pwd) { return(DownloadImage(imageUrl, ProxySettings.Proxy(imageUrl), null, usr, pwd)); }
public static IBitmap DownloadImage(string imageUrl) { return(DownloadImage(imageUrl, ProxySettings.Proxy(imageUrl))); }
async public static Task <string> HttpSendRequestAsync(string url, string methode, byte[] postBytes, string user, string password, Encoding encoding, int timeout = 0) { HttpWebResponse httpResponse; int trys = 0; while (true) { HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url); if (!user.Equals(String.Empty) || !password.Equals(string.Empty)) { string auth = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + password)); httpRequest.Headers.Add("Authorization", auth); } //HttpWReq.Timeout = timeout; httpRequest.Method = methode; if (timeout > 0) { httpRequest.Timeout = timeout; } //ProxySettings settings = new ProxySettings(); //HttpWReq.Proxy = settings.Proxy(url); httpRequest.Proxy = ProxySettings.Proxy(url); if (postBytes != null) { httpRequest.ContentLength = postBytes.Length; try { Stream stream = httpRequest.GetRequestStream(); stream.Write(postBytes, 0, postBytes.Length); stream.Flush(); stream.Close(); } catch (Exception e) { //log("[email protected]_ServletExec:\n"+e.Message,""); LastErrorMessage = e.Message; return(null); } } else { httpRequest.ContentLength = 0; } try { httpResponse = (HttpWebResponse)await httpRequest.GetResponseAsync(); break; } catch (Exception ex) { trys++; if (trys > 5) { throw (ex); } } } using (Stream stream = httpResponse.GetResponseStream()) { int Bytes2Read = 3500000; Byte[] b = new Byte[Bytes2Read]; MemoryStream memStream = new MemoryStream(); while (Bytes2Read > 0) { int len = stream.Read(b, 0, Bytes2Read); if (len == 0) { break; } memStream.Write(b, 0, len); } memStream.Position = 0; string s = encoding.GetString(memStream.GetBuffer()).Trim(' ', '\0'); memStream.Close(); memStream.Dispose(); return(s); } }
public static string DownloadXml(string url, string usr, string pwd) { return(DownloadXml(url, ProxySettings.Proxy(url), usr, pwd)); }
public static MemoryStream DownloadStream(string url, string usr, string pwd) { return(DownloadStream(url, ProxySettings.Proxy(url), null, usr, pwd)); }
public static MemoryStream DownloadStream(string url) { return(DownloadStream(url, ProxySettings.Proxy(url))); }