diff --git a/NewLife.Core/Http/HttpHelper.cs b/NewLife.Core/Http/HttpHelper.cs
index f9c5bf8..26ce148 100644
--- a/NewLife.Core/Http/HttpHelper.cs
+++ b/NewLife.Core/Http/HttpHelper.cs
@@ -7,9 +7,7 @@ using System.Threading.Tasks;
using NewLife.Collections;
using NewLife.Data;
using NewLife.Security;
-#if !NET40
using System.Net.Http;
-#endif
namespace NewLife.Http
{
@@ -165,7 +163,6 @@ namespace NewLife.Http
#endregion
#region 高级功能扩展
-#if !NET40
/// <summary>下载文件</summary>
/// <param name="client"></param>
/// <param name="address"></param>
@@ -175,9 +172,12 @@ namespace NewLife.Http
var rs = await client.GetStreamAsync(address);
fileName.EnsureDirectory(true);
using var fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
+#if NET4
+ fs.CopyTo(rs);
+#else
await fs.CopyToAsync(rs);
- }
#endif
+ }
#endregion
#region WebSocket
diff --git a/NewLife.Core/NewLife.Core.csproj b/NewLife.Core/NewLife.Core.csproj
index c58d887..75780c0 100644
--- a/NewLife.Core/NewLife.Core.csproj
+++ b/NewLife.Core/NewLife.Core.csproj
@@ -73,6 +73,7 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System.Management" />
+ <PackageReference Include="System.Net.Http" Version="2.0.20710" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Agent\**" />
diff --git a/NewLife.Core/Remoting/ApiHelper.cs b/NewLife.Core/Remoting/ApiHelper.cs
index aa48c20..4458020 100644
--- a/NewLife.Core/Remoting/ApiHelper.cs
+++ b/NewLife.Core/Remoting/ApiHelper.cs
@@ -1,5 +1,4 @@
-#if !NET4
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -216,5 +215,4 @@ namespace NewLife.Remoting
}
#endregion
}
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/NewLife.Core/Remoting/ApiHttpClient.cs b/NewLife.Core/Remoting/ApiHttpClient.cs
index 3c393b8..cda3514 100644
--- a/NewLife.Core/Remoting/ApiHttpClient.cs
+++ b/NewLife.Core/Remoting/ApiHttpClient.cs
@@ -1,5 +1,4 @@
-#if !NET4
-using System;
+using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
@@ -16,6 +15,9 @@ using NewLife.Log;
using NewLife.Reflection;
using NewLife.Serialization;
using NewLife.Threading;
+#if !NET4
+using TaskEx = System.Threading.Tasks.Task;
+#endif
namespace NewLife.Remoting
{
@@ -125,7 +127,7 @@ namespace NewLife.Remoting
/// <param name="action">服务操作</param>
/// <param name="args">参数</param>
/// <returns></returns>
- TResult IApiClient.Invoke<TResult>(String action, Object args) => Task.Run(() => InvokeAsync<TResult>(HttpMethod.Post, action, args)).Result;
+ TResult IApiClient.Invoke<TResult>(String action, Object args) => TaskEx.Run(() => InvokeAsync<TResult>(HttpMethod.Post, action, args)).Result;
#endregion
#region 构造请求
@@ -324,5 +326,4 @@ namespace NewLife.Remoting
public void WriteLog(String format, params Object[] args) => Log?.Info(format, args);
#endregion
}
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/NewLife.Core/Web/OAuth/GithubClient.cs b/NewLife.Core/Web/OAuth/GithubClient.cs
index 9f359ca..26e266a 100644
--- a/NewLife.Core/Web/OAuth/GithubClient.cs
+++ b/NewLife.Core/Web/OAuth/GithubClient.cs
@@ -30,7 +30,6 @@ namespace NewLife.Web.OAuth
if (dic.ContainsKey("bio")) Detail = dic["bio"].Trim();
}
-#if !NET4
private System.Net.Http.HttpClient _Client;
/// <summary>创建客户端</summary>
@@ -54,6 +53,5 @@ namespace NewLife.Web.OAuth
}
return LastHtml = _Client.GetStringAsync(url).Result;
}
-#endif
}
}
\ No newline at end of file