你如何编码 URL在安卓?
我以为是这样的:
final String encodedURL = URLEncoder.encode(urlAsString, "UTF-8");
URL url = new URL(encodedURL);
http://
在 urlAsString
替换为 http%3A%2F%2F
在 encodedURL
然后我得到一个 java.net.MalformedURLException
当我使用 URL 时。
您不会对整个 URL 进行编码,只对来自“不可靠来源”的部分进行编码。
String query = URLEncoder.encode("apples oranges", "utf-8");
String url = "http://stackoverflow.com/search?q=" + query;
val query: String = URLEncoder.encode("apples oranges", "utf-8")
val url = "http://stackoverflow.com/search?q=$query"
String uri = Uri.parse("http://...")
.buildUpon()
.appendQueryParameter("key", "val")
.build().toString();
关于android - Android 中的 URL 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3286067/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |