Flutter:执行http.put请求并更改JSON / API中的字符串状态

时间:2019-05-01 15:12:35

标签: json api flutter django-rest-framework

因此,我有一个具有值(“状态”:“开始”)的api,我想更改为:(“状态”:“完成”)。如果有人对Flutter中的http.put请求有想法,请随时提供帮助:)

API:

GET /api/task/29/
HTTP 200 OK
Allow: GET, POST, PUT, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
"id": 29,
"description": "Berlinmurens Fall",
"state": "started",
"assigned_users": [
    {
        "username": "hugo",
        "fullname": "Hugo Johnsson"
    }
],
"subtasks": []
}

JSON:

{"id":29,"description":"Berlinmurens Fall","state":"started","assigned_users":[{"username":"hugo","fullname":"Hugo Johnsson"}],"subtasks":[]}

放置请求:

putRequest() async {

String url = "--URL--";

final Map<String, dynamic> jsonDataaa = {
  "state": "done"
};

var response = await http.put(
    Uri.encodeFull(url),
    headers: { "Accept" : "application/json"},
    body: json.encode(jsonDataaa),
    encoding: Encoding.getByName("utf-8"),
);

return response;
}

我要做什么:

final Map<String, dynamic> jsonDataaa = {
  "id": 29,
  "description": "Berlinmurens Fall",
  "state": "done",
  "assigned_users": [
    {
      "username": "hugo",
      "fullname": "Hugo Johnsson"
    }
  ],
  "subtasks": []
};

1 个答案:

答案 0 :(得分:0)

您可以在flutter中使用补丁方法发送单个字段。 看看此链接Http-Methods in flutter