Home > Software engineering >  Make the request keeping the parameter string array
Make the request keeping the parameter string array

Time:10-11

I add 2 fields on my update request and I still didnt found a way to pass these 2 fields. I try someting link StringArrayContent, or ArrayContent that does not exist. I also try MultipartContent. How can I sent my request keeping downloadableInternal and downloadableExternal as string array? The values usually are empty [] or ["original", "pdf"]

return new ShowpadUpdateAssetRequest()
        {
            ExternalFileUri = externalFileUri,
            externalDate = externalDate,
            externalId = externalId,
            file = file,
            name = name,
            isDivisionShared = isDivisionShared,
            downloadableInternal = downloadableInternal,
            downloadableExternal = downloadableExternal,
            Url = url,
            Bearer = bearer,
            ResponseType = typeof(ShowpadUpdateAssetResponse),
            Content = new MultipartFormDataContent()
            {
                {new StringContent(externalId), nameof(externalId)},
                {new StringContent(name), nameof(name)},
                {new StringContent(externalDate), nameof(externalDate)},
                {new StringContent(isDivisionShared.ToString()), nameof(isDivisionShared) },                    
                {new StringContent(downloadableInternal.ToString())  ,nameof(downloadableInternal) },
                {new StringContent(downloadableExternal.ToString()) ,nameof(downloadableExternal) },
                {new ByteArrayContent((await fileContent.ReadAsByteArrayAsync())), nameof(file), file}
            }
        };

CodePudding user response:

This depends on how your service handles the request. Here is an example you can try. You can also try to remove the [] suffix, some service may regard repetitive query parameters as an array.

var c = new MultipartFormDataContent();
var key = nameof(downloadableInternal)   "[]";
foreach(string data in downloadableInternal)
   c.Add(new StringContent(data), key);
  • Related