.net 5.0改成6.0 修复外网文件上传bug
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Getf_Service_Transfer_Client_Service_HttpHandler
|
||||
{
|
||||
public class BodyEntity
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string commond { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public byte[] bytes { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string FileName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -16,6 +16,7 @@ using System.Reflection;
|
||||
using System.Net.Http;
|
||||
using Furion.RemoteRequest.Extensions;
|
||||
using Furion.RemoteRequest;
|
||||
using System.Security.Policy;
|
||||
|
||||
namespace Getf_Service_Transfer_Client_Service_HttpHandler
|
||||
{
|
||||
@@ -51,13 +52,31 @@ namespace Getf_Service_Transfer_Client_Service_HttpHandler
|
||||
}
|
||||
object r;
|
||||
SetHead(httpRequst, jObject["Head"]);
|
||||
httpRequst.SetBody(jObject["Data"].ToString());
|
||||
if (data.Length > 0)
|
||||
var bodyData = jObject["Data"];
|
||||
var bodyParam = jObject["Param"];
|
||||
if (data != null && data.Length > 0)
|
||||
{
|
||||
httpRequst.SetRequestUrl(url + "byte");
|
||||
httpRequst.SetBody(new { FileName = jObject["Data"]["fileName"].ToString(), bytes = data });
|
||||
BodyEntity be = new();
|
||||
if (bodyData != null)
|
||||
{
|
||||
if (bodyData["commond"] != null)
|
||||
be.commond = bodyData["commond"].ToString();
|
||||
if (bodyData["fileName"] != null)
|
||||
be.FileName = bodyData["fileName"].ToString();
|
||||
be.bytes = data;
|
||||
}
|
||||
httpRequst.SetBody(be);
|
||||
_LogHelper.Info($"body:{Newtonsoft.Json.JsonConvert.SerializeObject(be)}");
|
||||
}
|
||||
var response = httpRequst.SendAsync().Result;
|
||||
else
|
||||
{
|
||||
if (bodyParam != null)
|
||||
httpRequst.SetBody(bodyParam.ToString());
|
||||
if (bodyData != null)
|
||||
httpRequst.SetBody(bodyData.ToString());
|
||||
}
|
||||
var response = httpRequst.SendAsync()?.Result;
|
||||
if (IsTextContentType(response.Content.Headers.ContentType.MediaType))
|
||||
{
|
||||
r = response.Content.ReadAsStringAsync().Result;
|
||||
@@ -102,7 +121,8 @@ namespace Getf_Service_Transfer_Client_Service_HttpHandler
|
||||
catch (Exception e)
|
||||
{
|
||||
msg = e.Message;
|
||||
_LogHelper.Info("3:请求错误原因为:" + msg);
|
||||
_LogHelper.Info($"3:请求错误原因为:93段接口:url:{url},参数:{jObject["Data"]},结果:{msg},{e.StackTrace}");
|
||||
//_LogHelper.Info("3:请求错误原因为:" + msg + "," + e.StackTrace);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -200,12 +220,14 @@ namespace Getf_Service_Transfer_Client_Service_HttpHandler
|
||||
{
|
||||
foreach (JProperty elem in head)
|
||||
{
|
||||
var name = elem.Name;
|
||||
var value = elem.Value.ToString();
|
||||
dic.Add(name, value);
|
||||
var name = elem?.Name;
|
||||
var value = elem?.Value?.ToString();
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
dic.Add(name, value);
|
||||
}
|
||||
}
|
||||
httprequest.SetHeaders(dic);
|
||||
_LogHelper.Info($"6:请求header:{dic}");
|
||||
}
|
||||
|
||||
private void SetHead(HttpWebRequest httpWebRequest, string method, string headStr)
|
||||
@@ -282,7 +304,8 @@ namespace Getf_Service_Transfer_Client_Service_HttpHandler
|
||||
{
|
||||
if (contentType == null) return true;
|
||||
contentType = contentType.ToLower();
|
||||
var list = new string[] { "text/", "application/json", "application/xml" };
|
||||
//"text/",
|
||||
var list = new string[] { "application/json", "application/xml" };
|
||||
return list.Any(m => contentType.Contains(m));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<UserSecretsId>dotnet-Getf_Service_Transfer_core_client-A49AB986-D7BC-4882-BAB1-48CAF75741A2</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user