简体   繁体   English

RestSharp库发送列表对象

[英]RestSharp library sending list objects

I have problem with sending list to api using RestSharp library. 我在使用RestSharp库将列表发送到api时遇到问题。

public class MedicalExaminationSend
{
    public List<FileModel> Files { get; set; }

    public int PersonId { get; set; }
    public string SessionID { get; set; }
    public List<TestClass> TestModel { get; set; }
}

and I have client method 我有客户方法

            var request = new RestRequest();
            request.Method = Method.POST;
            request.AddHeader("Content-Type", "multipart/form-data");
            foreach (var item in examination.Files)
            {
                if(!string.IsNullOrEmpty(item.Path))
                    request.AddFile("Files", item.Path);
            }
            request.AddObject(examination);
            request.RequestFormat = DataFormat.Json;

But in api TestModel list is empty. 但是在api中,TestModel列表为空。 If i added as parameters 如果我添加为参数

foreach(var item in TestModel)
{
   request.AddParameter("TestModel",item)
}

In api list TestModel has only one element(first). 在api列表中,TestModel仅具有一个元素(第一个)。 How I can send list using multipart (because i also sending files)? 如何使用多部分发送列表(因为我也发送文件)?

I do not know RestSharp - but did you already try to set the testModel data via AddParameter (eg as List, or put them in an array first)? 我不知道RestSharp-但是您是否已经尝试通过AddParameter设置testModel数据(例如,作为List或首先将它们放在数组中)?

request.AddParameter("TestModel",TestModel)

What is the result in that case? 那样的结果是什么?

我将列表更改为数组,并且可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM