颤振 PUT 请求

Flutter PUT request

我正在尝试将我的 python 代码转换为 flutter,但无法这样做。尝试执行放置请求以更新网站上的数据。这是我用 python.

写的原始看跌请求
import requests
 
url = "https://my.website.com/api/request/12"
headers = {"user_key":"kfrrt-000234-as12321-1h58dm66a"}
input_data = '''{
    "request": {
        "comment": "New comment",
        "status": {
            "request_status": "Open"
        }
    }
}'''
data = {'input_data': input_data}
response = requests.put(url,headers=headers,data=data,verify=False)

到目前为止,我所掌握的内容:

  postTaskInfo()async{

    var jsonMP= {'request": {"comment": "New comment","status": {"request_status": "Open"}}'};

    String jsonString= jsonEncode(jsonMP);



    var url = 'https://my.website.com/api/request/12';

    await http.put(url, body: jsonString, headers: {"user_key":"kfrrt-000234-as12321-1h58dm66a"} ).then((response){
      setState(() {
        print(response.body);
      });
    });
}
I get an error " Unhandled Exception: Converting object to an encodable object failed: Instance of '_CompactLinkedHashSet

谢谢!

问题是由于 json编码未能将非 json 数据编码为字符串,因此更正 jsonMP 变量。

你的:

var jsonMP= {'request": {"comment": "New comment","status": {"request_status": "Open"}}'};

应该是

的形式
var jsonMP = {
  "request": {
    "comment": "New comment",
    "status": {"request_status": "Open"}
  }
};