【问题标题】:does the data sent to the server using http Post update the servers API url?使用 http Post 发送到服务器的数据是否会更新服务器 API url?
【发布时间】:2020-05-15 15:51:28
【问题描述】:

我是 Flutter 的新手,所以如果您认为问题上下文错误,请更新它,我正在从 SQl 服务器获取数据到我的 Flutter 应用程序,并且我还想在用户填写完毕后将信息发送回服务器出一个表格,我使用 http.post 并且我正确地得到了响应的正文但是当我打开服务器 URL(api url)时,我没有看到它更新了我发布到它的新信息,有人可以告诉我 Post 是怎样的应该工作吗?

【问题讨论】:

    标签: sql http flutter post dart


    【解决方案1】:

    我也是 Flutter 的新手,这是我如何理解它的一个工作示例

    class HttpService {
    createUser(String name, String lastname) async {
        Map data = {'name': name, 'lastname': lastname};
        var body = json.encode(data);
        var jsonResponse = null;
        var response = await http.post(serverUrl + "/create/",
            headers: {
              HttpHeaders.authorizationHeader: '**Token_here_if_you_use_it**',
              HttpHeaders.contentTypeHeader: "application/json",
              }, body: body);
        jsonResponse = json.decode(response.body);
        if (response.statusCode == 201) {
          jsonResponse = json.decode(response.body);
          if (jsonResponse != null) {
            print(jsonResponse.toString());
          }
        } else {
          print(jsonResponse.toString());
        }
      } 
    }
    

    在你的 main.dart 中:

    final HttpService httpService = HttpService();
    httpService.createUser(name,lastname);
    

    【讨论】:

    • 你好,这有点像代码的类型,那不是我的问题,
    • 我说当我将数据作为 post(url, body: {“data”: “name”}) 发送时,例如它没有在 API 中显示我添加了名称.. 我该怎么做确保服务器得到我发布到它的数据
    • @azheen “它没有在 API 中显示”是什么意思?什么是“API”?你是在说你的服务器后端吗?
    • 是的后端
    • 它是 NodeJs 后端还是什么?你有一些可以发布的代码吗?还是你问怎么做?
    猜你喜欢
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-29
    • 1970-01-01
    • 2018-04-17
    • 2012-12-29
    相关资源
    最近更新 更多