PKHeX/PKHeX.WinForms/Util/NetUtil.cs
Kurt 4e9b6be8e5 Convert console output to debug output
output messages are now no longer in release builds, as they are only
visible when debugging in an IDE.
2017-07-01 19:43:51 -07:00

42 lines
1.3 KiB
C#

using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
namespace PKHeX.WinForms
{
public static class NetUtil
{
public static string GetStringFromURL(string webURL)
{
try
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(webURL);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
var reader = new StreamReader(httpWebResponse.GetResponseStream());
return reader.ReadToEnd();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
return null;
}
}
public static Image GetImageFromURL(string webURL)
{
try
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(webURL);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebResponse.GetResponseStream();
return stream != null ? Image.FromStream(stream) : null;
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
return null;
}
}
}
}