I have a situation where part of my code sets a URL segment to a value, and then calls the code that executes the request with a retry if authentication fails.
Part of refreshing the authentication data retrieves the correct value of the URL segment. So, I need to call AddUrlSegment again with the new, proper value and then execute the request again, now with the proper value.
But that doesn't work. RestSharp always uses the original value of the URL segment. Here is a mock up of the code that illustrates it:
RestClient client = new RestClient();
var request = new RestRequest("https://api.example.com/orgs/{segment}/something");
request.AddUrlSegment("segment", 1);
var url1 = client.BuildUri(request);
request.AddUrlSegment("segment", 2);
var url2 = client.BuildUri(request);
After running this code, I would have expected url1 to be {https://api.example.com/orgs/1/something}
which it is. And I would have expected url2 to be {https://api.example.com/orgs/2/something}
which it is not. It is the same as url1.
Is there something different that I need to do to get url2 to use the updated segment value?
AddUrlSegmentcall (if that's even possible!) before you try to add another (i.e. either the second add is ignored, because it already has a value for the segment called "segment", or the first call takes precedence). Or alternatively, you need to create a newRestRequest.