-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reuse HttpClient in .NET 6.0 version to enable keep-alive.
Update Twitch client ID.
- Loading branch information
Showing
6 changed files
with
62 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.IO; | ||
|
||
#if NETFRAMEWORK | ||
using System.Net; | ||
#else | ||
using System.Net.Http; | ||
#endif | ||
|
||
namespace RechatTool { | ||
internal class TwitchApi5Client : IDisposable { | ||
#if !NETFRAMEWORK | ||
private readonly HttpClient _httpClient = new(); | ||
#endif | ||
|
||
public void Dispose() { | ||
#if !NETFRAMEWORK | ||
_httpClient.Dispose(); | ||
#endif | ||
} | ||
|
||
public string Request(string url) { | ||
#if NETFRAMEWORK | ||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); | ||
request.Accept = "application/vnd.twitchtv.v5+json"; | ||
request.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko"); | ||
using HttpWebResponse response = (HttpWebResponse)request.GetResponse(); | ||
using StreamReader responseStream = new(response.GetResponseStream()); | ||
return responseStream.ReadToEnd(); | ||
#else | ||
using HttpRequestMessage request = new(HttpMethod.Get, url); | ||
request.Headers.Add("Accept", "application/vnd.twitchtv.v5+json"); | ||
request.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko"); | ||
using HttpResponseMessage response = _httpClient.Send(request); | ||
using StreamReader responseStream = new(response.Content.ReadAsStream()); | ||
return responseStream.ReadToEnd(); | ||
#endif | ||
} | ||
} | ||
} |