Skip to content

Commit

Permalink
#1166 Исправляет авторизацию, добавляет System.Text.Encoding.CodePages
Browse files Browse the repository at this point in the history
  • Loading branch information
inyutin-maxim committed Jun 24, 2021
1 parent 7faa445 commit ca02b57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
13 changes: 8 additions & 5 deletions VkNet/Utils/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -34,15 +35,16 @@ public RestClient(HttpClient httpClient, ILogger<RestClient> logger)
public IWebProxy Proxy { get; set; }

/// <inheritdoc />
[Obsolete("Use HttpClient to configure timeout. Documentation reference https://github.com/vknet/vk/wiki/Proxy-Configuration", true)]
[Obsolete("Use HttpClient to configure timeout. Documentation reference https://github.com/vknet/vk/wiki/Proxy-Configuration",
true)]
public TimeSpan Timeout { get; set; }

/// <inheritdoc />
public Task<HttpResponse<string>> GetAsync(Uri uri, IEnumerable<KeyValuePair<string, string>> parameters)
{
var url = Url.Combine(uri.ToString(), Url.QueryFrom(parameters.ToArray()));

_logger?.LogDebug($"GET request: {url}");
_logger?.LogDebug("GET request: {Url}", url);

return CallAsync(() => HttpClient.GetAsync(new Uri(url)));
}
Expand Down Expand Up @@ -71,10 +73,11 @@ private async Task<HttpResponse<string>> CallAsync(Func<Task<HttpResponseMessage
{
var response = await method().ConfigureAwait(false);

var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

var bytes = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
var encoding = Encoding.GetEncoding(1251);
var content = encoding.GetString(bytes, 0, bytes.Length);
_logger?.LogDebug($"Response:{Environment.NewLine}{Utilities.PrettyPrintJson(content)}");
var requestUri = response.RequestMessage.RequestUri;
var requestUri = response.RequestMessage?.RequestUri;
var responseUri = response.Headers.Location;

return response.IsSuccessStatusCode
Expand Down
21 changes: 15 additions & 6 deletions VkNet/VkNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AsyncFixer" Version="1.5.1" PrivateAssets="all"/>
<PackageReference Include="HtmlAgilityPack" Version="1.11.33"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha" PrivateAssets="all"/>
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.23.0.32424" PrivateAssets="all"/>
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" PrivateAssets="all"/>
<PackageReference Include="AsyncFixer" Version="1.5.1" PrivateAssets="all" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.34" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha" PrivateAssets="all" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.25.0.33663" PrivateAssets="all" />
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net461'">
Expand All @@ -65,6 +65,7 @@
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="[5.0.1,)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="[5.0.0,)" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
Expand All @@ -83,4 +84,12 @@
<None Include="..\tools\vknet-icon.PNG" Pack="true" PackagePath="\" />
<None Include="..\LICENCE" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
</ItemGroup>
</Project>

0 comments on commit ca02b57

Please sign in to comment.