/// <summary> /// Loads and parses a response from an EH URL /// </summary> /// <param name="sAddress"></param> public static gmetadata LoadMetadata(string sAddress) { string sEHResponse = string.Empty; gmetadata gmManga = null; bool bException = true; //exit if there (probably) isn't an internet connection if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { return(gmManga); } //set up connection ServicePointManager.DefaultConnectionLimit = 64; HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://g.e-hentai.org/api.php"); rq.ContentType = "application/json; charset=UTF-8"; rq.Method = "POST"; rq.Timeout = 5000; rq.KeepAlive = false; rq.Proxy = null; try { //send formatted request to EH API using (Stream s = rq.GetRequestStream()) { byte[] byContent = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(new csEHAPI(sAddress))); s.Write(byContent, 0, byContent.Length); } using (StreamReader sr = new StreamReader(((HttpWebResponse)rq.GetResponse()).GetResponseStream())) { sEHResponse = sr.ReadToEnd(); rq.Abort(); } bException = false; } catch (WebException exc) { SQL.LogMessage(exc, SQL.EventType.HandledException, sAddress); } finally { //parse returned JSON if (!bException && !string.IsNullOrWhiteSpace(sEHResponse)) { gmManga = new gmetadata(sEHResponse); } } return(gmManga); }
/// <summary> /// Loads and parses a response from an EH URL /// </summary> /// <param name="sAddress"></param> public static gmetadata LoadMetadata(string sAddress) { string sEHResponse = string.Empty; gmetadata gmManga = null; bool bException = true; //exit if there (probably) isn't an internet connection if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) return gmManga; //set up connection ServicePointManager.DefaultConnectionLimit = 64; HttpWebRequest rq = (HttpWebRequest) WebRequest.Create("http://g.e-hentai.org/api.php"); rq.ContentType = "application/json; charset=UTF-8"; rq.Method = "POST"; rq.Timeout = 5000; rq.KeepAlive = false; rq.Proxy = null; try { //send formatted request to EH API using (Stream s = rq.GetRequestStream()) { byte[] byContent = Encoding.ASCII.GetBytes( JsonConvert.SerializeObject(new csEHAPI(sAddress))); s.Write(byContent, 0, byContent.Length); } using (StreamReader sr = new StreamReader(( (HttpWebResponse)rq.GetResponse()).GetResponseStream())) { sEHResponse = sr.ReadToEnd(); rq.Abort(); } bException = false; } catch (WebException exc) { Console.WriteLine(exc.Message); } finally { //parse returned JSON if (!bException && !string.IsNullOrWhiteSpace(sEHResponse)) { gmManga = new gmetadata(sEHResponse); } } return gmManga; }