BaseUrl with urlSegment parameter to replace is not replaced when BaseUrl has absolute resource path

661 views
Skip to first unread message

Mario Arriaga

unread,
Oct 19, 2020, 4:39:35 PM10/19/20
to RestSharp
## Expected Behavior
Sending request with RestClient "BaseUrl" set to a url that ends in a UrlSegment to replace ("api/app/{userId}/feature/**{rowId}**") and Put RestRequest with empty "Resource" should get urlSegments replaced correctly

## Actual Behavior
Sending request with RestClient "BaseUrl" set to a url that ends in a UrlSegment to replace ("api/app/{userId}/feature/**{rowId}**") and Put RestRequest with empty "Resource" doesnot get urlSegments replaced correctly - "BadRquest" is returned with response Uri as "api/app/**{userId}**/feature/**{rowId}**"

If using below way, replacement works correctly during Execute: 
`RestRequest.Resource = "api/app/**{userId}**/feature/**{rowId}**";

RestClient.BaseUrl = "www.example.com";
RestClient.Execute(RestRequest);`

## Steps to Reproduce the Problem

  1. Have handy an endpoint with url segment to replace as api/app/**{userId}**/feature/**{rowId}**
  2.Create RestClient with default constructor `Client.BaseUrl = new Uri("www.example.com/api/app/**{userId}**/feature/**{rowId}**");`
  3. Create RestRequest with default constructor `new RestRequest();`
  4. Add required headers, request format and Put method as needed `Request.Method = Method.PUT`
  5. Add Url Segments as needed: 
`Request.AddUrlSegment("userId", "12345");
Request.AddUrlSegment("rowId", "67890");`
  6. Add a body, I did this when reproducing issue:
`Request.AddBody(dto);`
Here's json request payload structure:
"{
  "someId": [
    "D14192C0824644E89C0FAC59013C2384"
  ],
  "SomeValue": {
    "rowId": "ASDF2345SDFHK",
    "valueId": "ASDF2345SDFHK",
    "valueChanged": "2020-10-19T19:11:06.596815",
    "value": 200,
    "someColumnId": "ASDF2345SDFHK",
    "someColumnChanged": "2020-10-19T19:11:01.553725"
  }
}"
  7. Send request:
`RestClient.Execute(RestRequest);`

## Specifications

  - Version:  v105.2.3
  - Platform: Windows 10 x64

Mario Arriaga

unread,
Oct 19, 2020, 11:05:03 PM10/19/20
to RestSharp
False alarm, there were some non-printable characters in resource url.

Kind regards,
Mario Arriaga

Reply all
Reply to author
Forward
0 new messages