PKHeX/PKHeX.Core/Util/NetUtil.cs
Kurt fc754b346b
File scoped namespaces (#3529)
[Language Reference](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces)

Updates all the files, one less level of indentation.

Some small changes were made to API surfaces, renaming `PKM pkm` -> `PKM pk`, and `LegalityAnalysis.pkm` -> `LegalityAnalysis.Entity`
2022-06-18 11:04:24 -07:00

39 lines
1 KiB
C#

using System;
using System.Diagnostics;
using System.IO;
using System.Net;
namespace PKHeX.Core;
public static class NetUtil
{
public static string? GetStringFromURL(Uri url)
{
try
{
var stream = GetStreamFromURL(url);
if (stream == null)
return null;
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
// No internet?
catch (Exception e)
{
Debug.WriteLine(e.Message);
return null;
}
}
private static Stream? GetStreamFromURL(Uri url)
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
// The GitHub API will fail if no user agent is provided
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36";
var httpWebResponse = httpWebRequest.GetResponse();
return httpWebResponse.GetResponseStream();
}
}