2

Hi Um quite new to Java and I want to encode Hello World it to Hello%20World . But when I use URLEncoder.encode it will encode the string as Hello+World and when we try to pass it via a Request to IIS it ll consider as a threat. How to encode as i mentioned ? Thank you in advance.

not 0x12
  • 19,360
  • 22
  • 67
  • 133
  • 1
    You may want to check out http://stackoverflow.com/a/4605816/680925. – Perception Apr 22 '13 at 11:30
  • I doubt that this is really the reason that IIS considers it to be a threat, as you say. – Jesper Apr 22 '13 at 11:33
  • http://www.ifinity.com.au/Blog/EntryId/60/404-Error-in-IIS-7-when-using-a-Url-with-a-plus-sign-in-the-path I got to know the IIS risk from there – not 0x12 Apr 22 '13 at 11:36
  • 1
    URLEncoder is ok. Replacing + by %20 is a specific behaviour, java.lang.String.replace works perfectly for that. –  Apr 22 '13 at 12:45

1 Answers1

-1

This only works for real URLs

URL u = new URL("Hello World");
String path = u.getPath();
Praneeth Peiris
  • 2,008
  • 20
  • 40