|
16 | 16 | using System.Runtime.Serialization;
|
17 | 17 | using RestSharp.Extensions;
|
18 | 18 | using static RestSharp.KnownHeaders;
|
| 19 | +// ReSharper disable SuggestBaseTypeForParameter |
19 | 20 |
|
20 | 21 | namespace RestSharp;
|
21 | 22 |
|
@@ -121,17 +122,24 @@ void AddBody(bool hasPostParameters) {
|
121 | 122 | void AddPostParameters(ParametersCollection? postParameters) {
|
122 | 123 | if (postParameters.IsEmpty()) return;
|
123 | 124 |
|
124 |
| - var mpContent = Content as MultipartFormDataContent ?? new MultipartFormDataContent(); |
125 |
| - |
126 |
| - // we got the multipart form already instantiated, just add parameters to it |
127 |
| - foreach (var postParameter in postParameters!) { |
128 |
| - mpContent.Add( |
129 |
| - new StringContent(postParameter.Value!.ToString()!, _client.Options.Encoding, postParameter.ContentType), |
130 |
| - postParameter.Name! |
| 125 | + if (Content is MultipartFormDataContent mpContent) { |
| 126 | + // we got the multipart form already instantiated, just add parameters to it |
| 127 | + foreach (var postParameter in postParameters!) { |
| 128 | + mpContent.Add( |
| 129 | + new StringContent(postParameter.Value!.ToString()!, _client.Options.Encoding, postParameter.ContentType), |
| 130 | + postParameter.Name! |
| 131 | + ); |
| 132 | + } |
| 133 | + } |
| 134 | + else { |
| 135 | + // we should not have anything else except the parameters, so we send them as form URL encoded |
| 136 | + var formContent = new FormUrlEncodedContent( |
| 137 | + _request.Parameters |
| 138 | + .Where(x => x.Type == ParameterType.GetOrPost) |
| 139 | + .Select(x => new KeyValuePair<string, string>(x.Name!, x.Value!.ToString()!))! |
131 | 140 | );
|
| 141 | + Content = formContent; |
132 | 142 | }
|
133 |
| - |
134 |
| - Content = mpContent; |
135 | 143 | }
|
136 | 144 |
|
137 | 145 | void AddHeaders() {
|
|
0 commit comments