Geni Lou

Geni Lou

  • NA
  • 101
  • 22.4k

JSON RestClient 107

Feb 8 2022 3:26 PM

How can I make the body dynamically especially the type which is list? 

            var options = new RestClientOptions(baseUrl){
                ThrowOnAnyError = true,
                Timeout         = 1000
            };
            var client          = new RestClient(options);
            RestRequest request = new RestRequest("/authtoken", Method.Post);

            request.AddHeader("Content-Type", "application/json");

            var body = @"{" + "\n" +
            @"  ""clientId"": 1111," + "\n" +
            @"  ""clientPassword"": ""password""," + "\n" +
            @"  ""type"": [" + "\n" +
            @"    ""admin""," + "\n" +
            @"    ""sa""" + "\n" +
            @"  ]" + "\n" +
            @"}";

            request.AddJsonBody(body);
            var response = client.PostAsync<Authentication>(request);
            return response.Result.token;


Answers (1)