Skip to content

Commit

Permalink
Exception was being thrown: "utf-8 is not a supported encoding name".
Browse files Browse the repository at this point in the history
    Handled exception with "ReadAsStreamAsync" instead of "ReadAsStringAsync" within a try/catch clause.

Exception was being thrown: "The request was aborted: Could not create SSL/TLS secure channel.".
    Handled exception by setting " ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;" in the constructor.

Exception was being thrown: "The connection closed unexpectedly.".
    Handled exception by setting: "ServicePointManager.Expect100Continue = false;" on line 520 (not in constructor so that it is conditional, for now).
  • Loading branch information
nstevens1040 committed Jul 21, 2021
1 parent bb6277d commit d0076ab
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
36 changes: 34 additions & 2 deletions Execute.HttpRequest/Execute.HttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class Utils
{
public void Ctor()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
string resourceName = new AssemblyName(args.Name).Name + ".dll";
Expand Down Expand Up @@ -516,6 +517,7 @@ public async Task<RetObject> SendHttp(string uri, HttpMethod method = null, Orde
);
break;
default:
ServicePointManager.Expect100Continue = false;
res = await client.SendAsync(
(new HttpRequestMessage(method, uri)
{
Expand All @@ -531,7 +533,22 @@ public async Task<RetObject> SendHttp(string uri, HttpMethod method = null, Orde
}
else
{
htmlString = res.Content.ReadAsStringAsync().Result;
try
{
htmlString = res.Content.ReadAsStringAsync().Result;
}
catch
{
except = true;
}
if (except)
{
var responseStream = await res.Content.ReadAsStreamAsync().ConfigureAwait(false);
using (var sr = new StreamReader(responseStream, Encoding.UTF8))
{
htmlString = await sr.ReadToEndAsync().ConfigureAwait(false);
}
}
}
try
{
Expand Down Expand Up @@ -592,7 +609,22 @@ public async Task<RetObject> SendHttp(string uri, HttpMethod method = null, Orde
}
else
{
htmlString = res.Content.ReadAsStringAsync().Result;
try
{
htmlString = res.Content.ReadAsStringAsync().Result;
}
catch
{
except = true;
}
if (except)
{
var responseStream = await res.Content.ReadAsStreamAsync().ConfigureAwait(false);
using (var sr = new StreamReader(responseStream, Encoding.UTF8))
{
htmlString = await sr.ReadToEndAsync().ConfigureAwait(false);
}
}
}
try
{
Expand Down
2 changes: 1 addition & 1 deletion Execute.HttpRequest/Execute.HttpRequest.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Execute.HttpRequest</id>
<version>1.2.0</version>
<version>1.2.1</version>
<title>Execute.HttpRequest</title>
<authors>nstevens1040</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
2 changes: 1 addition & 1 deletion Execute.HttpRequest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ deploy:
api_key:
secure: f+MLRpFFOj9kyNxbFyIt2n5I/dR48bmJ6qXRB/ageJ/18o61FDhu61IZgwk9KfqD
- provider: GitHub
tag: v1.2.0
release: v1.2.0 stable
tag: v1.2.1
release: v1.2.1 stable
description: 'Pushing Quick-Start.ps1'
auth_token:
secure: ElzOGqa44YRqwJ9jKgjBNDbPEmxb1Mg3I+0TxsPQg8OdUSOA8T8DwkwoKofTXMQT
Expand Down

0 comments on commit d0076ab

Please sign in to comment.