Shachaf.Gortler
Shachaf.Gortler

Reputation: 5735

Uri Rest resource name formating

I have resource I'm trying to retrieve with a GET opertaion

The resource look like this , the resousce is defined by user name which can contain domain information . i.e var userName = @"Domain\myname" I'm having issues reformatting the Uri

what I've tried is to 1. var resource = string.Format("/user/{0}/order", Uri.EscapeDataString(userName ));

  1. var resource = string.Format("/user/{0}/order", HttpUtility.UrlEncode(userName ));

I'm sending data to back end using .Net HttpClient I get an error stating end point not found . when I look at the call at the debugger I see the endpoint is trying to be accessed: user/Domain/myname/order

what can be done , so a resource parameter could contain domain '\' characters

Upvotes: 0

Views: 47

Answers (1)

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57214

I'm not a C# guy, so I don't know The Answer[tm], but I can tell you a few things to look for

  1. String.Format is likely to be the wrong tool in the toolkit. You aren't trying to format a string, you are trying to format a URI. So you should be looking for something like a UriTemplate

  2. You should make sure that you know what the correct result is. That's defined by the first appendix of the URI specification.

Upvotes: 1

Related Questions