How to parse or split URL Address in Java?

后端 未结 2 487
南笙
南笙 2020-11-30 07:48

If I have url address.

https://graph.facebook.com/me/home?limit=25&since=1374196005

Can I get(or split) parameters (avoiding hard coding)?

Like t

2条回答
  •  Happy的楠姐
    2020-11-30 08:31

    Use Android's Uri class. http://developer.android.com/reference/android/net/Uri.html

    Uri uri = Uri.parse("https://graph.facebook.com/me/home?limit=25&since=1374196005");
    String protocol = uri.getScheme();
    String server = uri.getAuthority();
    String path = uri.getPath();
    Set args = uri.getQueryParameterNames();
    String limit = uri.getQueryParameter("limit");
    

提交回复
热议问题