public byte[] GetPage(string url, bool useKey, typeMaskBits mirrorType, bool forceReload) { string mirr = ""; switch (mirrorType) { case typeMaskBits.tmXML: mirr = this.XMLMirror; break; case typeMaskBits.tmBanner: mirr = this.BannerMirror; break; case typeMaskBits.tmZIP: mirr = this.ZIPMirror; break; default: case typeMaskBits.tmMainSite: mirr = "http://www.thetvdb.com"; break; } if (url.StartsWith("/")) { url = url.Substring(1); } if (!mirr.EndsWith("/")) { mirr += "/"; } string theURL = mirr; if (mirrorType != typeMaskBits.tmBanner) { theURL += "api/"; } else { theURL += "banners/"; } if (useKey) { theURL += APIKey() + "/"; } theURL += url; //HttpWebRequest ^wr = dynamic_cast<HttpWebRequest ^>(HttpWebRequest::Create(theURL)); //wr->Timeout = 10000; // 10 seconds //wr->Method = "GET"; //wr->KeepAlive = false; System.Net.WebClient wc = new System.Net.WebClient(); if (forceReload) { wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.Reload); } try { byte[] r = wc.DownloadData(theURL); //HttpWebResponse ^wres = dynamic_cast<HttpWebResponse ^>(wr->GetResponse()); //Stream ^str = wres->GetResponseStream(); //array<unsigned char> ^r = gcnew array<unsigned char>((int)str->Length); //str->Read(r, 0, (int)str->Length); if (!url.EndsWith(".zip")) { System.Diagnostics.Debug.Print("Downloaded " + url + ", " + r.Length + " bytes"); } return(r); } catch (WebException e) { this.LastError = this.CurrentDLTask + " : " + e.Message; return(null); } }
public byte[] GetPage(string url, bool useKey, typeMaskBits mirrorType, bool forceReload) { string mirr = ""; switch (mirrorType) { case typeMaskBits.tmXML: mirr = this.XMLMirror; break; case typeMaskBits.tmBanner: mirr = this.BannerMirror; break; case typeMaskBits.tmZIP: mirr = this.ZIPMirror; break; default: case typeMaskBits.tmMainSite: mirr = "http://www.thetvdb.com"; break; } if (url.StartsWith("/")) url = url.Substring(1); if (!mirr.EndsWith("/")) mirr += "/"; string theURL = mirr; if (mirrorType != typeMaskBits.tmBanner) theURL += "api/"; else theURL += "banners/"; if (useKey) theURL += APIKey() + "/"; theURL += url; //HttpWebRequest ^wr = dynamic_cast<HttpWebRequest ^>(HttpWebRequest::Create(theURL)); //wr->Timeout = 10000; // 10 seconds //wr->Method = "GET"; //wr->KeepAlive = false; System.Net.WebClient wc = new System.Net.WebClient(); if (forceReload) wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.Reload); try { byte[] r = wc.DownloadData(theURL); //HttpWebResponse ^wres = dynamic_cast<HttpWebResponse ^>(wr->GetResponse()); //Stream ^str = wres->GetResponseStream(); //array<unsigned char> ^r = gcnew array<unsigned char>((int)str->Length); //str->Read(r, 0, (int)str->Length); if (!url.EndsWith(".zip")) System.Diagnostics.Debug.Print("Downloaded " + theURL + ", " + r.Length + " bytes"); return r; } catch (WebException e) { System.Diagnostics.Debug.Print(this.CurrentDLTask + " : " + e.Message + " : " + theURL); this.LastError = this.CurrentDLTask + " : " + e.Message; return null; } }