Results 1 to 4 of 4
  1. #1
    dug201 is offline Member
    Join Date
    Aug 2012
    Location
    London, UK
    Posts
    15
    Rep Power
    0

    Default URLEncoder.encode

    Hello;

    I'm playing around with url encding a string, but its not encoding it as expected.

    for example I have this code

    Java Code:
    String urlEncode = URLEncoder.encode("chars: & % < > ?","UTF-8");
    
    System.out.println("CATCH-->XML Request:" + urlEncode);
    The output is:

    charsA+++C+-NaN+F

    But should the desired output not be:

    chars%3A%20%26%20%25%20%3C%20%3E%20%3F

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,901
    Rep Power
    25

    Default Re: URLEncoder.encode

    Strange. The output I get is:
    urlEncode:chars%3A+%26+%25+%3C+%3E+%3F
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    dug201 is offline Member
    Join Date
    Aug 2012
    Location
    London, UK
    Posts
    15
    Rep Power
    0

    Default Re: URLEncoder.encode

    Quote Originally Posted by Norm View Post
    Strange. The output I get is:
    Yes, that's the output I also want / was expecting. Would you know what would cause the bad output I'm getting? Can it be fixed in the Jave code or this is a JVM issue?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,901
    Rep Power
    25

    Default Re: URLEncoder.encode

    I copied and pasted the two lines of code into a program, compiled and executed it on Win7 with java 1.6 & 1.7 and got the results posted.
    I have No idea why your program would generate something different.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. encode decode
    By jaki312 in forum New To Java
    Replies: 3
    Last Post: 03-13-2012, 09:12 PM
  2. UTF-8 Encode?
    By FiniteRed in forum New To Java
    Replies: 1
    Last Post: 02-18-2011, 08:38 PM
  3. Encode Image into Base64 value.
    By onlyabhinav in forum New To Java
    Replies: 3
    Last Post: 01-25-2011, 08:44 AM
  4. Encode data to torrent?
    By greatmajestics in forum AWT / Swing
    Replies: 0
    Last Post: 04-28-2010, 05:12 PM
  5. Url Encode
    By Sean_J in forum New To Java
    Replies: 0
    Last Post: 03-19-2010, 03:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •