public static string getJSON(string url) { try { using (WebClient wc = new WebClient()) { wc.Headers.Add("User-Agent: " + Adv.Default.UserAgent); string json = wc.DownloadString(url); byte[] bytes = Encoding.ASCII.GetBytes(json); using (var stream = new MemoryStream(bytes)) { var quotas = new XmlDictionaryReaderQuotas(); var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, quotas); var xml = XDocument.Load(jsonReader); stream.Flush(); stream.Close(); return(xml.ToString()); } } } catch (WebException WebE) { Debug.Print(WebE.ToString()); MessageBox.Show(WebE.ToString()); return(null); throw WebE; } catch (Exception ex) { Debug.Print(ex.ToString()); MessageBox.Show(ex.ToString()); return(null); throw ex; } }
public static string getJSON(string url) { try { using (WebClient wc = new WebClient()) { wc.Headers.Add("User-Agent: SheetMaker/" + Properties.Settings.Default.currentVersion.ToString()); string json = wc.DownloadString(url); byte[] bytes = Encoding.ASCII.GetBytes(json); using (var stream = new MemoryStream(bytes)) { var quotas = new XmlDictionaryReaderQuotas(); var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, quotas); var xml = XDocument.Load(jsonReader); stream.Flush(); stream.Close(); return(xml.ToString()); } } } catch (WebException WebE) { Debug.Print(WebE.ToString()); ErrorLog.reportWebError(WebE, url); return(null); } catch (Exception ex) { Debug.Print(ex.ToString()); ErrorLog.reportError(ex.ToString()); return(null); } }
public static string getJSON(string url) { if (!Properties.Settings.Default.jsonSupport) { return(null); } try { using (WebClient wc = new WebClient()) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; wc.Headers.Add("User-Agent: " + Program.UserAgent); string json = wc.DownloadString(url); byte[] bytes = Encoding.ASCII.GetBytes(json); using (var stream = new MemoryStream(bytes)) { var quotas = new XmlDictionaryReaderQuotas(); var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, quotas); var xml = XDocument.Load(jsonReader); stream.Flush(); stream.Close(); return(xml.ToString()); } } } catch (WebException WebE) { Debug.Print(WebE.ToString()); ErrorLog.reportWebError(WebE, url); return(null); throw WebE; } catch (Exception ex) { Debug.Print(ex.ToString()); ErrorLog.reportError(ex); return(null); throw ex; } }