2023-06-27
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Configuration;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Security.Policy;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
@@ -144,11 +145,15 @@ namespace WebAPI.Controllers
|
||||
/// <param name="toDoItem"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task DownloadDocument([FromBody] Model.ToDoItem toDoItem)
|
||||
public async Task<Model.ResponeData> DownloadDocument([FromBody] Model.SaveOnlineFileItem toDoItem)
|
||||
//public async Task<Model.ResponeData> DownloadDocument( string UrlStr, string PCUrl)
|
||||
{
|
||||
var responeData = new Model.ResponeData();
|
||||
|
||||
HttpClient _httpClient = new HttpClient();
|
||||
try
|
||||
{
|
||||
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
|
||||
// 发送 GET 请求以获取文件内容
|
||||
var response = await _httpClient.GetAsync(toDoItem.UrlStr);
|
||||
response.EnsureSuccessStatusCode();
|
||||
@@ -166,15 +171,17 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
await response.Content.CopyToAsync(fileStream);
|
||||
}
|
||||
|
||||
Console.WriteLine("文件已成功下载并保存到本地。");
|
||||
responeData.data = "文件已成功下载并保存到本地";
|
||||
// Console.WriteLine("文件已成功下载并保存到本地。");
|
||||
|
||||
}
|
||||
|
||||
return responeData;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"下载文件时出现错误:{ex.Message}");
|
||||
responeData.code=0;
|
||||
responeData.message = $"下载文件时出现错误:{ex.Message}";
|
||||
return responeData;
|
||||
}
|
||||
}
|
||||
#region 附件上传
|
||||
|
||||
Reference in New Issue
Block a user