Java URL encoding of query string parameters

前端 未结 12 1456
清歌不尽
清歌不尽 2020-11-21 05:27

Say I have a URL

http://example.com/query?q=

and I have a query entered by the user such as:

random word £500 bank

12条回答
  •  没有蜡笔的小新
    2020-11-21 05:58

    I found an easy solution to your question. I also wanted to use an encoded URL but nothing helped me.

    http://example.com/query?q=random%20word%20%A3500%20bank%20%24

    to use String example = "random word £500 bank $"; you can you below code.

    String example = "random word £500 bank $";
    String URL = "http://example.com/query?q=" + example.replaceAll(" ","%20");
    

提交回复
热议问题