UriMatcher 是否能够匹配自定义 http 链接?

发布于 2024-10-02 13:24:22 字数 360 浏览 0 评论 0原文

我想使用 UriMatcher 来匹配自定义 http 链接。

我有以下代码:

UriMatcher mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
mUriMatcher.addURI("myLink", "http://a.b.c/?id=", 1);
mUriMatcher.addURI("myLink", "http://d.e.f/?id=", 2);
int match = mUriMatcher.match(Uri.parse("http://a.b.c/?id=123"));

但我总是在比赛结果中得到“-1”......

I would like to use UriMatcher to match custom http links.

I have following code:

UriMatcher mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
mUriMatcher.addURI("myLink", "http://a.b.c/?id=", 1);
mUriMatcher.addURI("myLink", "http://d.e.f/?id=", 2);
int match = mUriMatcher.match(Uri.parse("http://a.b.c/?id=123"));

But I always get "-1" in match result...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃梦幻 2024-10-09 13:24:22

UriMatcher 匹配以下形式的 Uris:

scheme://<authority>/<path>

它忽略查询字符串(url 中 ? 之后出现的任何内容)

您使用以下方式注册匹配器:

mUriMatcher.addURI(authority, path, result);

因此,在上面的简单示例中,您无法区分带有或不带有查询字符串的相同 URL ,但可以在域名上进行匹配。使用:

mUriMatcher.addURI('a.b.c', '/', 1);
mUriMatcher.addURI('d.e.f', '/', 2);

您可以在每个匹配处理程序中使用 UrlQuerySanitizer 来决定您需要的查询内容是否存在。

UriMatcher matches Uris of the form:

scheme://<authority>/<path>

It ignores the query string (anything appearing after ? in the url)

You register with the matcher using:

mUriMatcher.addURI(authority, path, result);

So, in your simple example above, you can not distinguish between the same URL with or without a query string, but you can match on the domain name. Use:

mUriMatcher.addURI('a.b.c', '/', 1);
mUriMatcher.addURI('d.e.f', '/', 2);

You can use UrlQuerySanitizer within each match handler to decide whether the query things you need are present or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文