How do I decode URLs in Java?

Asked 2 years ago, Updated 2 years ago, 124 views

in Java https%3A%2F%2Fmywebsite%2Fdocs%2Fenglish%2Fsite%2Fmybook.do%3Frequest_type These chords https://mywebsite/docs/english/site/mybook.do&request_type I'd like to change it like this.

class StringUTF 
{
    public static void main(String[] args) 
    {
        try{
            String url = 
               "https%3A%2F%2Fmywebsite%2Fdocs%2Fenglish%2Fsite%2Fmybook.do" +
               "%3Frequest_type%3D%26type%3Dprivate";

            System.out.println(url+"Hello World!------->" +
                new String(url.getBytes("UTF-8"),"ASCII"));
        }
        catch(Exception E){
        }
    }
}

I tried it like this, but it didn't work. How shall I do it?

java url-encoding

2022-09-21 19:30

1 Answers

String result = java.net.URLDecoder.decode(url, "UTF-8"); You can do it in this way.


2022-09-21 19:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.