|
12 | 12 | // See the License for the specific language governing permissions and
|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
| 15 | +using System.Net; |
15 | 16 | using System.Net.Http.Headers;
|
16 | 17 | using System.Runtime.Serialization;
|
17 | 18 | using RestSharp.Extensions;
|
@@ -157,13 +158,16 @@ void AddPostParameters(ParametersCollection? postParameters) {
|
157 | 158 | }
|
158 | 159 | }
|
159 | 160 | else {
|
160 |
| - // we should not have anything else except the parameters, so we send them as form URL encoded |
161 |
| - var formContent = new FormUrlEncodedContent( |
162 |
| - _request.Parameters |
163 |
| - .Where(x => x.Type == ParameterType.GetOrPost) |
164 |
| - .Select(x => new KeyValuePair<string, string>(x.Name!, x.Value!.ToString()!))! |
165 |
| - ); |
166 |
| - Content = formContent; |
| 161 | + // we should not have anything else except the parameters, so we send them as form URL encoded. However due |
| 162 | + // to bugs in HttpClient FormUrlEncodedContent (see https://github.com/restsharp/RestSharp/issues/1814) we |
| 163 | + // do the encoding ourselves using WebUtility.UrlEncode instead. |
| 164 | + var formData = _request.Parameters |
| 165 | + .Where(x => x.Type == ParameterType.GetOrPost) |
| 166 | + .Select(x => new KeyValuePair<string, string>(x.Name!, x.Value!.ToString()!))!; |
| 167 | + var encodedItems = formData.Select(i => $"{WebUtility.UrlEncode(i.Key)}={WebUtility.UrlEncode(i.Value)}"/*.Replace("%20", "+")*/); |
| 168 | + var encodedContent = new StringContent(string.Join("&", encodedItems), null, "application/x-www-form-urlencoded"); |
| 169 | + |
| 170 | + Content = encodedContent; |
167 | 171 | }
|
168 | 172 | }
|
169 | 173 |
|
|
0 commit comments