How to make HTTP POST request with url encoded body in flutter?

前端 未结 8 1527
南笙
南笙 2020-12-01 03:59

I\'m trying to make an post request in flutter with content type as url encoded. When I write body : json.encode(data), it encodes to plain text.

If I

8条回答
  •  旧时难觅i
    2020-12-01 04:11

    you need to use json.encode

    example;

    var match = {
      "homeTeam": {"team": "Team A"},
      "awayTeam": {"team": "Team B"}
    };
    var response = await post(Uri.parse(url),
        headers: {
          "Accept": "application/json",
          "Content-Type": "application/x-www-form-urlencoded"
        },
        body: json.encode(match),
        encoding: Encoding.getByName("utf-8"));
    

提交回复
热议问题