使用Dart解析URI以提取查询参数 [英] Parsing a URI to extract query parameters, with Dart

查看:76
本文介绍了使用Dart解析URI以提取查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以这种形式提出要求:

I have a request in this form:

http://website/index.html?name=MyName&token=12345

有没有一种方法可以从该URL中提取名称和令牌?始终有一个选项可以遍历所有字符并以这种方式保存,但是我正在Dart中寻求更优雅的解决方案.

Is there a way how to extract name and token from this url? There is always an option to iterate through all characters and save it that way, but I am looking for more elegant solution in Dart.

推荐答案

var uri = Uri.parse('http://website/index.html?name=MyName&token=12345');
uri.queryParameters.forEach((k, v) {
   print('key: $k - value: $v');
});

key: name - value: MyName
key: token - value: 12345

这篇关于使用Dart解析URI以提取查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆