?Java?,????java.net.URLEncoder
??URL???????????????,?????????application/x-www-form-urlencoded MIME?????????????:
encode(String s, String enc)
: ????s
????????enc
?????encode(String s)
: ???????(UTF-8)????s
?????
??????????,??????URLEncoder
?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=Java URL Encoding"; try { // ??UTF-8????URL???? String encodedUrl = URLEncoder.encode(url, "UTF-8"); System.out.println("Encoded URL: " + encodedUrl); } catch (UnsupportedEncodingException e) { // ?????????,?????? e.printStackTrace(); } } }
??????,???????????????ASCII???URL???,????URLEncoder.encode()
???????application/x-www-form-urlencoded MIME?????,?????????URL?
??:??????,?????????(UTF-8),??????????????,????????????