http request with params

7,565

Solution 1

You can't add params to a request, you need to add it to an URL you use for the request. The Uri class provides methods for that

var uri = Uri.parse('http://test/testing');
uri = uri.replace(query: 'user=x');
print(uri);

or

uri = uri.replace(queryParameters: <String, String>{'user': 'x'});

or

final uri = Uri.parse('http://test/testing').replace(query: 'user=x');

Solution 2

It seems like a more direct way to do it is to use Uri.http.

// http://example.org/path?q=dart.
Uri.http("example.org", "/path", { "q" : "dart" });

Notes:

  • The query parameters are { "q" : "dart" }.
  • Uri.https() works the same way.
Share:
7,565
Little Monkey
Author by

Little Monkey

I'm just a little monkey!

Updated on December 06, 2022

Comments

  • Little Monkey
    Little Monkey over 1 year

    Is there some function that adds the request params to an http request in way that you don't have to do it "manually"? For example, if I want to put "user": "x" as param of my request, in a way to achieve something like

    http:test/testing?user=x
    

    how can I do it?