简体   繁体   中英

RestSharp library sending list objects

I have problem with sending list to api using RestSharp library.

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. If i added as parameters

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

In api list TestModel has only one element(first). 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)?

request.AddParameter("TestModel",TestModel)

What is the result in that case?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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