Http: Post array using http in flutter

Created on 11 Oct 2020  路  1Comment  路  Source: dart-lang/http

How to post array using http?

var headers = {"Accept": "application/json"};
      var url = "https://...."
      var response = await http.post(url,
          body: {
           ....
          },

I have a param named commentList. I need to pass comment[0], comment[1]... inside body.

Most helpful comment

Works as you would expect:

List<String> comments = ["1st", "2nd", "3rd"];
Map<String, dynamic> args = {"comments": comments};
String url = "myurl.com";
var body = json.encode(args);
final response = await http
    .post(url, body: body, headers: {'Content-type': 'application/json'});

>All comments

Works as you would expect:

List<String> comments = ["1st", "2nd", "3rd"];
Map<String, dynamic> args = {"comments": comments};
String url = "myurl.com";
var body = json.encode(args);
final response = await http
    .post(url, body: body, headers: {'Content-type': 'application/json'});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

drishit96 picture drishit96  路  3Comments

demos77 picture demos77  路  3Comments

DartBot picture DartBot  路  6Comments

Buckstabue picture Buckstabue  路  7Comments

KOGI picture KOGI  路  5Comments