且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Java中解析或分割URL地址?

更新时间:2023-11-26 11:55:28

使用Android的 Uri 类。 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();
设置< String> args = uri.getQueryParameterNames();
String limit = uri.getQueryParameter(limit);


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 this

https /// graph.facebook.com /// me/home /// {limit=25, sincse=1374196005}

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<String> args = uri.getQueryParameterNames();
String limit = uri.getQueryParameter("limit");