diff --git a/src/RestSharp/Request/RestRequest.cs b/src/RestSharp/Request/RestRequest.cs index 40b8e074c..bdb725b70 100644 --- a/src/RestSharp/Request/RestRequest.cs +++ b/src/RestSharp/Request/RestRequest.cs @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System.Net; using System.Net.Http.Headers; -using RestSharp.Authenticators; -using RestSharp.Extensions; -using RestSharp.Interceptors; // ReSharper disable ReplaceSubstringWithRangeIndexer // ReSharper disable UnusedAutoPropertyAccessor.Global namespace RestSharp; +using Authenticators; +using Extensions; +using Interceptors; + /// /// Container for data used to make requests /// @@ -53,7 +53,7 @@ public RestRequest(string? resource, Method method = Method.Get) : this() { var queryParams = ParseQuery(Resource.Substring(queryStringStart + 1)); Resource = Resource.Substring(0, queryStringStart); - foreach (var param in queryParams) this.AddQueryParameter(param.Key, param.Value, false); + foreach (var param in queryParams) this.AddQueryParameter(param.Key, param.Value); return; @@ -84,12 +84,12 @@ public RestRequest(Uri resource, Method method = Method.Get) /// Always send a multipart/form-data request - even when no Files are present. /// public bool AlwaysMultipartFormData { get; set; } - + /// /// Always send a file as request content without multipart/form-data request - even when the request contains only one file parameter /// public bool AlwaysSingleFileAsContent { get; set; } - + /// /// When set to true, parameter values in a multipart form data requests will be enclosed in /// quotation marks. Default is false. Enable it if the remote endpoint requires parameters @@ -232,7 +232,7 @@ public Func? AdvancedResponseWri _advancedResponseHandler = value; } } - + /// /// Request-level interceptors. Will be combined with client-level interceptors if set. /// @@ -255,4 +255,4 @@ public RestRequest RemoveParameter(Parameter parameter) { } internal RestRequest AddFile(FileParameter file) => this.With(x => x._files.Add(file)); -} +} \ No newline at end of file diff --git a/test/RestSharp.Tests/UrlBuilderTests.cs b/test/RestSharp.Tests/UrlBuilderTests.cs index 8db92717e..df937cddc 100644 --- a/test/RestSharp.Tests/UrlBuilderTests.cs +++ b/test/RestSharp.Tests/UrlBuilderTests.cs @@ -236,6 +236,16 @@ public void Should_use_ipv6_address() { actual.AbsoluteUri.Should().Be("https://[fe80::290:e8ff:fe8b:2537]:8443/api/v1/auth"); } + [Fact] + public void Should_encode_resource() { + const string baseUrl = "https://example.com"; + const string resource = "resource?param=value with spaces"; + + var request = new RestRequest(resource); + var uri = new Uri($"{baseUrl}/{resource}"); + AssertUri(baseUrl, request, uri.AbsoluteUri); + } + [Fact] public void Should_not_encode_pipe() { var request = new RestRequest("resource").AddQueryParameter("ids", "in:001|116", false);