Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing a URI to extract query parameters, with Dart

Tags:

dart

dart-html

I have a request in this form:

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

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.

like image 945
Vilda Avatar asked Aug 29 '14 17:08

Vilda


People also ask

How do you use URI Parse in flutter?

parse method Null safety Example: final uri = Uri. parse('https://example.com/api/fetch?limit=10,20,30&max=100'); print(uri); // https://example.com/api/fetch?limit=10,20,30&max=100 Uri. parse('::Not valid URI::'); // Throws FormatException.

How do you declare URI in darts?

If you have a URI object or a URI string, you can get its parts using URI fields such as path. To create a URI from a string, use the parse() static method. Example: Dart.


1 Answers

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 
like image 140
Günter Zöchbauer Avatar answered Oct 10 '22 22:10

Günter Zöchbauer