Flutter - http post 请求参数未被占用

Flutter - http post request parameter is not taken

我想通过 POST 请求从服务器获取动漫列表(这是一个搜索,所以我使用字符串参数发出 POST 请求)。我从网站上得到了一个有效的代码和 return 两到三个动画 - 这是正确的响应,我的应用程序 return 有一些动画列表。为什么会这样?我给出相同的参数 'hello'.

这是一个 Javascript 代码,它有效:

    let body = "name=" + encodeURIComponent(getParameterByName('search'));
    var req = new XMLHttpRequest();

    req.open("POST", "https://api.animevost.org/v1/search", true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    req.onload = function () {
        unpackLastTitles(req.response);
    };

    req.onerror = function () {
        alert("Загрузка не удалась");
    };
    console.log(9898, body, req);

    req.send(body);

这是我的 Flutter 代码,它 return 动漫的大列表(而不是搜索的)不管你搜索什么:

final response = await http.post(
          Uri.https('api.animevost.org', '/v1/search', {'name': tC.text}),
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Credentials": 'true',
            "Access-Control-Allow-Headers":
                "Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale",
            "Access-Control-Allow-Methods": "POST, OPTIONS"
          });

您必须将其作为正文参数发送。

final response = await http.post(
   Uri.https('api.animevost.org', '/v1/search'),
   body: {'name': tC.text}, // Setting as body parameter
   headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Credentials": 'true',
      "Access-Control-Allow-Headers":
         "Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale",
      "Access-Control-Allow-Methods": "POST, OPTIONS"
});