Skip to content

Commit

Permalink
修复.net core下无法重复读取的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Varorbc committed Aug 1, 2018
1 parent c7cc70d commit 7763f0d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
8 changes: 3 additions & 5 deletions src/PaySharp.Core/Notify/NotifyProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ public static GatewayData ReadNotifyData()
{
if (IsXmlData)
{
using (var reader = new StreamReader(HttpUtil.Body))
{
string xmlData = reader.ReadToEnd();
gatewayData.FromXml(xmlData);
}
var reader = new StreamReader(HttpUtil.Body);
var xmlData = reader.ReadToEnd();
gatewayData.FromXml(xmlData);
}
else
{
Expand Down
3 changes: 1 addition & 2 deletions src/PaySharp.Core/PaySharp.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<Title>PaySharp.Core</Title>
<Description>支付核心</Description>
<Version>1.0.5</Version>
<Version>1.0.6</Version>
<PackageTags>dotnetcore;pay;</PackageTags>
<PackageReleaseNotes>
修复.Net环境下,ip带端口的问题
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
50 changes: 40 additions & 10 deletions src/PaySharp.Core/Utils/HttpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ public static string LocalIpAddress
{
get
{
var ipAddress = Current.Connection.LocalIpAddress;
return IPAddress.IsLoopback(ipAddress) ?
IPAddress.Loopback.ToString() :
ipAddress.MapToIPv4().ToString();
try
{
var ipAddress = Current.Connection.LocalIpAddress;
return IPAddress.IsLoopback(ipAddress) ?
IPAddress.Loopback.ToString() :
ipAddress.MapToIPv4().ToString();
}
catch
{
return IPAddress.Loopback.ToString();
}
}
}

Expand All @@ -51,10 +58,17 @@ public static string RemoteIpAddress
{
get
{
var ipAddress = Current.Connection.RemoteIpAddress;
return IPAddress.IsLoopback(ipAddress) ?
IPAddress.Loopback.ToString() :
ipAddress.MapToIPv4().ToString();
try
{
var ipAddress = Current.Connection.RemoteIpAddress;
return IPAddress.IsLoopback(ipAddress) ?
IPAddress.Loopback.ToString() :
ipAddress.MapToIPv4().ToString();
}
catch
{
return IPAddress.Loopback.ToString();
}
}
}

Expand All @@ -76,7 +90,16 @@ public static Stream Body
get
{
var body = Current.Request.Body;
body.Position = 0;
try
{
if (body.CanSeek)
{
body.Position = 0;
}
}
catch
{ }

return body;
}
}
Expand Down Expand Up @@ -169,7 +192,14 @@ public static Stream Body
get
{
var inputStream = Current.Request.InputStream;
inputStream.Position = 0;
try
{
if (inputStream.CanSeek)
{
inputStream.Position = 0;
}
}
catch { }
return inputStream;
}
}
Expand Down

0 comments on commit 7763f0d

Please sign in to comment.