PKHeX/PKHeX.WinForms/Util/NetUtil.cs

42 lines
1.3 KiB
C#
Raw Normal View History

using System;
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);
2017-03-23 05:37:59 +00:00
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
var reader = new StreamReader(httpWebResponse.GetResponseStream());
return reader.ReadToEnd();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return null;
}
}
public static Image GetImageFromURL(string webURL)
{
try
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(webURL);
2017-03-23 05:37:59 +00:00
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebResponse.GetResponseStream();
return stream != null ? Image.FromStream(stream) : null;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return null;
}
}
}
}