0

I have a URI like this:

http://example.org/servers/bob@home/repositories/Examples/models

Now I want to deal with the fact that ideally I should encode the @ char in the URI.

Now if I use the System.Web.HttpUtility.UrlEncode it encodes the / and : etc.

http%3a%2f%2fexample.org%2fservers%2fbob%40home%2frepositories%2fExamples%2fmodels

So is there a way to encode the segments of the URI without messing up the separators etc. - without having to break the URI and encode each part?

sbarnby71
  • 584
  • 4
  • 7
  • 21
  • That uri does not have any characters that need encoding (https://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid), could you elaborate what is the actual problem you are trying to solve here? – Esko May 15 '19 at 11:14
  • The URI is then being sent out in an xml response and the consumer of the response is having issues with their 3rd party parser not being happy about the @ in the URI, they are expecting a %40 - so I'm trying to help them out even though the URI as it stands is valid. – sbarnby71 May 15 '19 at 11:19
  • Ok. If the problem is specific to this one case, maybe you are just better off by simply replacing the one character with what is needed? – Esko May 15 '19 at 11:23
  • I was thinking down that path, but know that once I do that, they will then encounter an issue with another character like + or &. – sbarnby71 May 15 '19 at 11:24
  • If the third party can not give you specifications what their system can/can't digest, you can't do much of anything. I'v been in this situation many times before and if I can help it, I won't give in to ridiculous requirements that make no sense. Always this is not possible of course, but at least they need to give you specs of what they need. – Esko May 15 '19 at 11:30
  • Totally agree and I'm loathed to make any kind of change. I guess I was more curious over how over-jealous the UrlEncode is. – sbarnby71 May 15 '19 at 11:34

1 Answers1

-1

You can replace @ character to another character Like this string strURI = "http://example.org/servers/bob@home/repositories/Examples/models"; strURI = strURI.Replace("@", "^");

if you require original string then you can replace it with @ character strURI = strURI.Replace("^", "@");