【问题标题】:Decode URL after redirect link重定向链接后解码 URL
【发布时间】:2013-08-03 05:08:03
【问题描述】:

我有一个未编码的 url1

String url1="http://bitake.com/params/?attribute=3"

这里 url2(url1 重定向后的 url) 被编码

String url2="http://search.bitake.com/params/?attr=48%e6%99%82%e9%96%93%e3%82"

我使用此链接打开 Intent 浏览器

Intent browserIntent = new Intent("android.intent.action.VIEW",   
                                      Uri.parse(URLDecoder.decode(url));
startActivity(browserIntent);

我想通过代码从 url1 获取 url2..然后解码 url2 可以在 web 中打开 我该怎么办?

【问题讨论】:

    标签: java android android-intent browser decode


    【解决方案1】:

    我认为您的 url1 不是有效的 url。无法通过 utf8 和 GB 解码为有效的 url

    【讨论】:

      【解决方案2】:

      您的 URL1 不是有效的 URL。 URLDecoder.decode(string url) 已弃用。您应该使用 URLDecode.decode(String url, String enc) 其中 enc 是字符编码。

      另外% 必须编码为%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();
            }
         }
      }
      

      【讨论】:

      • 这里我只想获取url1(重定向后的url)来解码url1。
      • 对不起,我不明白你在问什么。
      • 尝试在我的解决方案中提供的代码中使用 url1。看看是否能解决你的问题。我的 url1 和你的不一样。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-16
      • 1970-01-01
      • 1970-01-01
      • 2013-06-03
      • 1970-01-01
      相关资源
      最近更新 更多