2016-08-31 03:31:14 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
2017-02-01 03:35:18 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2016-08-31 03:31:14 +00:00
|
|
|
|
{
|
2017-02-04 16:18:48 +00:00
|
|
|
|
public static class NetUtil
|
2016-08-31 03:31:14 +00:00
|
|
|
|
{
|
|
|
|
|
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());
|
2016-08-31 03:31:14 +00:00
|
|
|
|
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();
|
2016-08-31 03:31:14 +00:00
|
|
|
|
return stream != null ? Image.FromStream(stream) : null;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.Message);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|