0

I have URL:

http://localhost:8128/WCF8bcPgServices/EventService/Event/GETPLS/station=E2SKGR&secondstation=%2fE2SKGR

Class Uri convert URL into :

http://localhost:8128/WCF8bcPgServices/EventService/Event/GETPLS/station=E2SKGR&secondstation=/E2SKGR

I trayed call constructor

new Uri("http://localhost:8128/WCF8bcPgServices/EventService/Event/GETPLS/station=E2SKGR&secondstation=%2fE2SKGR", true)

no effect

Why class Uri convert %2f into character '/'?

misak
  • 342
  • 1
  • 2
  • 13
  • 1
    Should that constructor have quotes around the url? – Denise Skidmore Apr 18 '13 at 13:16
  • When passing a string to the URI constructor, the returned URI has escape encodings done for you, so %2f is the encoded version of the '/' character, and thus you get '/' in the returned URI. – Laurence Moroney Apr 18 '13 at 13:20
  • 1
    You still have the original encoded string in [`Uri.OriginalString`](http://msdn.microsoft.com/en-us/library/system.uri.originalstring.aspx). – Tim Schmelter Apr 18 '13 at 13:24

3 Answers3

1

The %2f actually means '/'. in asciitable you can see, that 2f corresponds the the '/' character.

The percent-encoding is whats happens automatically.

Henrik Gering
  • 1,769
  • 16
  • 29
1

The two are 100% equivalent.

Actually, it's only necessary to encode the character '/' to %2f if it is used in the path (prior to the & ampersand). Used after the & ampersand (in the query string) there is no ambiguity, and it can therefore be used in unescaped format. The Uri class is clever and knows this, and therefore removes the unnecessary escaping that you applied in your original url.

You are creating apparently buggy behaviour by not escaping all of the characters in your url. Either you've omitted a ? character somewhere in your original url, or you need to encode the reserved characters in the url to remove ambiguity.

spender
  • 117,338
  • 33
  • 229
  • 351
  • @mistak: After further research, I am not happy that this answer is correct, and I would advise you to remove your "Accept vote". – spender Apr 19 '13 at 14:29
  • Hi, problem wasn't with Uri. Adress: http://localhost:8128/WCF8bcPgServices/EventService/Event/ is WCF (webHttpBinding) service adress defined by template: [WebGet(UriTemplate = "/Event/{exe_name}/{pars}")] I think, there is error in WCF (webHttpBinding) binding string parameter which contains %2f. – misak Apr 22 '13 at 08:14
  • Problem wants another issue :(. – misak Apr 22 '13 at 08:16
  • 1
    @misak: When I looked deeper into the issue, I found strange behaviour and opened this question about it: http://stackoverflow.com/questions/16107490/why-does-uri-behave-differently-for-different-schemes/16107589?noredirect=1#comment23002699_16107589 – spender Apr 22 '13 at 10:26
  • I trayed add tags uri into app.config: http://msdn.microsoft.com/en-us/library/ee656542(v=vs.100).aspx no effect :( – misak Apr 23 '13 at 07:37
0

This seems to be obsolete by now :

The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202

See the doc about it.

EDIT :

If you still need to access the full string that you passed to the constructor and avoid automatic conversion, you can use the property Uri.OriginalString which will return exactly what you gave to the constructor.

ForceMagic
  • 6,230
  • 12
  • 66
  • 88