7
HttpUtility.UrlEncode("!!!test", Encoding.GetEncoding("windows-1251"))

It doesn't encode ! to %21 - why?

Oded
  • 489,969
  • 99
  • 883
  • 1,009
kusanagi
  • 14,296
  • 20
  • 86
  • 111

1 Answers1

11

Because it is a valid character on a URL and doesn't need to be encoded.

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • 1
    but if i sniff a firefox, it encodes, also php function urlencode encodes too – kusanagi Mar 07 '11 at 13:51
  • @kusanagi - which means they are doing something that is not needed, at least when URL encoding is concerned. They may be doing that due to internal implementation considerations. – Oded Mar 07 '11 at 13:51
  • 1
    but server not accept '!' only '%21' so i need manually replace? – kusanagi Mar 07 '11 at 13:53
  • @kusanagi - What server? You didn't mention a server in your question. – Oded Mar 07 '11 at 13:54
  • 1
    http server, i make program post, so if i submit in firefox server accept '!' but my programm post request not accept – kusanagi Mar 07 '11 at 13:55
  • @kusanagi - What webserver? Did you attach a debugging proxy to see the actual request/response? Perhaps you should be asking a new question about this. – Oded Mar 07 '11 at 13:58
  • if i post value '!!!test' server get only 'test' but if i post'%21%21%21test' server get '!!!test' – kusanagi Mar 07 '11 at 14:00
  • 2
    @kusanagi - Looks like an issue with your web server or framework. It works fine on wikipedia: http://en.wikipedia.org/wiki/Yahoo! – Oded Mar 07 '11 at 14:04