mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-15 00:37:11 +00:00
66e669a42b
NetUtil simply can be static, which brings it inline with the other NetUtil.
41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
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);
|
|
HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
|
|
var reader = new StreamReader(httpWebReponse.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);
|
|
HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
|
|
Stream stream = httpWebReponse.GetResponseStream();
|
|
return stream != null ? Image.FromStream(stream) : null;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|