?Java?,????java.net.URLEncoder
?java.net.URLDecoder
??URL??????????????????????application/x-www-form-urlencoded MIME??????
- ?URL????:
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class URLEncodingExample { public static void main(String[] args) { String url = "https://example.com/search?q=????"; try { String encodedUrl = URLEncoder.encode(url, "UTF-8"); System.out.println("Encoded URL: " + encodedUrl); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }
- ?URL????:
import java.io.UnsupportedEncodingException; import java.net.URLDecoder; public class URLDecodingExample { public static void main(String[] args) { String encodedUrl = "https://example.com/search?q=你好世界"; try { String decodedUrl = URLDecoder.decode(encodedUrl, "UTF-8"); System.out.println("Decoded URL: " + decodedUrl); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }
??:???URLEncoder.encode()
?URLDecoder.decode()
?,???????(?"UTF-8")?????URL???????????????????