Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振镖HTTP POST请求主体在服务器端为空_Flutter_Dart - Fatal编程技术网

Flutter 颤振镖HTTP POST请求主体在服务器端为空

Flutter 颤振镖HTTP POST请求主体在服务器端为空,flutter,dart,Flutter,Dart,我正在开发一款颤振平板电脑应用程序。输入一个输入字段后,我将尝试向服务器发送post请求。以下是我为此调用的方法: Future < http.Response > _postRequest() async { print(globals.novaCoord.toString() + ' XYZXYZXYZXYZXYZ'); var url = globals.URL + 'api/nova_position'; Map data = {

我正在开发一款颤振平板电脑应用程序。输入一个输入字段后,我将尝试向服务器发送post请求。以下是我为此调用的方法:

    Future < http.Response > _postRequest() async {
    print(globals.novaCoord.toString() + ' XYZXYZXYZXYZXYZ');

    var url = globals.URL + 'api/nova_position';

    Map data = {
      'id_nova': '1',
      'position.x': '1',
      'position.y': '1',
      'position.z': '1',
      'position.pitch': '1',
      'position.yaw': '1',
      'position.roll': '1',
    };
    //encode Map to JSON
    var body = json.encode(data);

    http.Response response = await http.post(url,
      headers: {
        "Content-Type": "application/json"
      },
      body: body
    );
    print("${response.statusCode}");
    print("${response.body}");
    return response;
  }
但是,在服务器端,我接收到发送的请求的一个空正文,并收到以下错误:

(node:23939) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'x' of undefined

在这一点上我需要帮助。非常感谢您的帮助和指导。

您必须在提交Post请求之前编写代码 像


我希望您能得到解决方案。

在进入Post请求之前,您必须先编写JSONECODE 像

我希望您能得到解决方案。

使用http.post发送地图无法正确发送数据

要解决此问题,请将标题的内容类型更改为:

映射自定义标题={ ... 内容类型:application/json ... }; 然后,您可以使用http.post,如下所示:

http.postrl,headers:customHeaders,body; 使用http.post发送映射将无法正确发送数据

要解决此问题,请将标题的内容类型更改为:

映射自定义标题={ ... 内容类型:application/json ... }; 然后,您可以使用http.post,如下所示:

http.postrl,headers:customHeaders,body;
我找到的解决方案是简单地将Content Length:x添加到标题中,x是json正文的大小。

我找到的解决方案是简单地将Content Length:x添加到标题中,x是json正文的大小。

您在某处调用http.createServer吗?代码在哪里?你能和邮递员一起使用你的服务器吗?嗨@RichardHeap我有一个nodeJs服务器,甚至当我尝试与邮递员一起使用时,我发现服务器不知怎么的,有一个空的主体。我只需要确定服务器端。你在某处调用http.createServer吗?代码在哪里?你能和邮递员一起使用你的服务器吗?嗨@RichardHeap我有一个nodeJs服务器,甚至当我尝试与邮递员一起使用时,我发现服务器不知怎么的,有一个空的主体。我只需要确定服务器端。是的,你是正确的。完成建议的修复后,我有一个更新的代码。我现在确信我有一个关于服务器的问题。从邮递员那里收到的尸体也是空的。是的,你是对的。完成建议的修复后,我有一个更新的代码。我现在确信我有一个关于服务器的问题。从邮递员那里收到的尸体也是空的。
(node:23939) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'x' of undefined
String bodyF = jsonEncode(body);