public static Bitmap DownloadImage(string imageUrl, string usr, string pwd) { return(DownloadImage(imageUrl, ProxySettings.Proxy(imageUrl), null, usr, pwd)); }
public static Bitmap DownloadImage(string imageUrl) { return(DownloadImage(imageUrl, ProxySettings.Proxy(imageUrl))); }
public static string HttpSendRequest(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)httpRequest.GetResponse(); 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); } /* * using (StreamReader sr = new StreamReader(HttpWResp.GetResponseStream())) * { * string s; * System.IO.StringReader stgr = new System.IO.StringReader(sr.ReadToEnd()); * s = stgr.ReadToEnd(); * * 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))); }