I have a url1 that not be encoded
String url1="http://bitake.com/params/?attribute=3"
And here url2( url after redirect of url1) be encoded
String url2="http://search.bitake.com/params/?attr=48%e6%99%82%e9%96%93%e3%82"
I use this link to open browswer with Intent
Intent browserIntent = new Intent("android.intent.action.VIEW",
Uri.parse(URLDecoder.decode(url));
startActivity(browserIntent);
I want to get url2 from url1 by code..Then decode url2 to can open in web How must I do?
i think your url1 is not a valid url. Can not decode to a valid url neither by utf8 nor GB
You URL1 is not a valid URL. URLDecoder.decode(string url) is deprecated. You should use URLDecode.decode(String url, String enc) where enc is the character encoding.
Also %
must be encoded as %25
public class DecodeTest
{
public static void main(String[] args)
{
String url="http://bitake.com/params/?attribute=3";
String url1="http://search.bitake.com/params/?attr=48%25e6%2599%2582%25e9%2596%2593%25e3%2582%25";
try
{
System.out.println(URLDecoder.decode(url,"UTF-8"));
System.out.println(URLDecoder.decode(url1, "UTF-8"));
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.