.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">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using System.Reflection;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using Furion.RemoteRequest.Extensions;
|
using Furion.RemoteRequest.Extensions;
|
||||||
using Furion.RemoteRequest;
|
using Furion.RemoteRequest;
|
||||||
|
using System.Security.Policy;
|
||||||
|
|
||||||
namespace Getf_Service_Transfer_Client_Service_HttpHandler
|
namespace Getf_Service_Transfer_Client_Service_HttpHandler
|
||||||
{
|
{
|
||||||
@@ -51,13 +52,31 @@ namespace Getf_Service_Transfer_Client_Service_HttpHandler
|
|||||||
}
|
}
|
||||||
object r;
|
object r;
|
||||||
SetHead(httpRequst, jObject["Head"]);
|
SetHead(httpRequst, jObject["Head"]);
|
||||||
httpRequst.SetBody(jObject["Data"].ToString());
|
var bodyData = jObject["Data"];
|
||||||
if (data.Length > 0)
|
var bodyParam = jObject["Param"];
|
||||||
|
if (data != null && data.Length > 0)
|
||||||
{
|
{
|
||||||
httpRequst.SetRequestUrl(url + "byte");
|
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;
|
||||||
}
|
}
|
||||||
var response = httpRequst.SendAsync().Result;
|
httpRequst.SetBody(be);
|
||||||
|
_LogHelper.Info($"body:{Newtonsoft.Json.JsonConvert.SerializeObject(be)}");
|
||||||
|
}
|
||||||
|
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))
|
if (IsTextContentType(response.Content.Headers.ContentType.MediaType))
|
||||||
{
|
{
|
||||||
r = response.Content.ReadAsStringAsync().Result;
|
r = response.Content.ReadAsStringAsync().Result;
|
||||||
@@ -102,7 +121,8 @@ namespace Getf_Service_Transfer_Client_Service_HttpHandler
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
msg = e.Message;
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -200,12 +220,14 @@ namespace Getf_Service_Transfer_Client_Service_HttpHandler
|
|||||||
{
|
{
|
||||||
foreach (JProperty elem in head)
|
foreach (JProperty elem in head)
|
||||||
{
|
{
|
||||||
var name = elem.Name;
|
var name = elem?.Name;
|
||||||
var value = elem.Value.ToString();
|
var value = elem?.Value?.ToString();
|
||||||
|
if (!string.IsNullOrEmpty(name))
|
||||||
dic.Add(name, value);
|
dic.Add(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
httprequest.SetHeaders(dic);
|
httprequest.SetHeaders(dic);
|
||||||
|
_LogHelper.Info($"6:请求header:{dic}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetHead(HttpWebRequest httpWebRequest, string method, string headStr)
|
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;
|
if (contentType == null) return true;
|
||||||
contentType = contentType.ToLower();
|
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));
|
return list.Any(m => contentType.Contains(m));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<UserSecretsId>dotnet-Getf_Service_Transfer_core_client-A49AB986-D7BC-4882-BAB1-48CAF75741A2</UserSecretsId>
|
<UserSecretsId>dotnet-Getf_Service_Transfer_core_client-A49AB986-D7BC-4882-BAB1-48CAF75741A2</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user