修改上传文件接口 传输类型为 multipart/form-data

This commit is contained in:
范露尧
2023-03-13 12:36:48 +08:00
parent d0450c9585
commit e9935b16a9

View File

@@ -56,18 +56,36 @@ namespace Getf_Service_Transfer_Client_Service_HttpHandler
var bodyParam = jObject["Param"];
if (data != null && data.Length > 0)
{
httpRequst.SetRequestUrl(url + "byte");
BodyEntity be = new();
//httpRequst.SetRequestUrl(url + "byte");
//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)}");
httpRequst.SetContentType("multipart/form-data");
if (bodyData != null)
{
httpRequst.SetFiles(HttpFile.Create("file", data, "image.png"));
if (bodyData["commond"] != null)
be.commond = bodyData["commond"].ToString();
if (bodyData["fileName"] != null)
be.FileName = bodyData["fileName"].ToString();
be.bytes = data;
{
var dic = new Dictionary<string, object>();
var childs = bodyData["commond"].Children();
foreach (var child in childs)
{
var name = ((Newtonsoft.Json.Linq.JProperty)child).Name;
var value = ((Newtonsoft.Json.Linq.JProperty)child).Value.ToString();
dic.Add(name, value);
}
//httpRequst.SetBody(Newtonsoft.Json.JsonConvert.DeserializeObject(bodyData["commond"].ToString()), "multipart/form-data");
httpRequst.SetBody(dic, "multipart/form-data");
}
}
httpRequst.SetBody(be);
_LogHelper.Info($"body:{Newtonsoft.Json.JsonConvert.SerializeObject(be)}");
}
else
{