Ran*_*ize 5 java url urlencode
我需要在URL中编码参数值.如果我使用以下内容:
URLEncoder.encode(url, "UTF-8");
Run Code Online (Sandbox Code Playgroud)
对于这样的URL: http://localhost:8080/...
它将编码"://"等.我需要的是仅对从所有URL字符串开始的参数值进行编码.所以在这种情况下:
我想只编码2个参数值中的"blah"(当然是n个参数).
你最好的方法是什么?
谢谢
随机化
你正在以错误的方式使用URLEncoder.您应该分别编码每个参数值,然后将URL组合在一起.
例如
String url = "http://localhost/?q=" + URLEncoder.encode ("blah", "UTF-8") + "&d=" + URLEncoder.encode ("blah", "UTF-8");
Run Code Online (Sandbox Code Playgroud)