当我尝试从Flutter应用程序向运行在NodeMCU(带有Lua的微控制器)上的服务器发出请求时,出现以下错误:
composer require jenssegers/mongodb --ignore-platform-reqs
发生这种情况的行是:
DECLARE v_manager_id NUMERIC;
BEGIN
SELECT MANAGER_ID INTO v_manager_id, COUNT(MANAGER_ID)
FROM DEPARTMENTS
GROUP BY MANAGER_ID
HAVING COUNT(MANAGER_ID) > 1;
END;
'Accept'标头没有区别。
相反,如果我将其定向到任何其他URL(例如“ https://httpbin.org/get”),则请求将正确执行:
E/flutter (11080): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (11080): Invalid request method
E/flutter (11080): #0 IOClient.send (package:http/src/io_client.dart:64:7)
E/flutter (11080): <asynchronous suspension>
E/flutter (11080): #1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:171:38)
E/flutter (11080): <asynchronous suspension>
E/flutter (11080): #2 BaseClient.get (package:http/src/base_client.dart:34:5)
E/flutter (11080): #3 get.<anonymous closure> (package:http/http.dart:47:34)
E/flutter (11080): #4 _withClient (package:http/http.dart:167:20)
E/flutter (11080): <asynchronous suspension>
E/flutter (11080): #5 get (package:http/http.dart:47:3)
E/flutter (11080): #6 _MyHomePageState._sendGet1 (file:///D:/dev/repos/github/thing_client/lib/main.dart:62:33)
E/flutter (11080): <asynchronous suspension>
E/flutter (11080): #7 _MyHomePageState.build.<anonymous closure> (file:///D:/dev/repos/github/thing_client/lib/main.dart:137:17)
E/flutter (11080): #8 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:494:14)
E/flutter (11080): #9 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:549:30)
E/flutter (11080): #10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter (11080): #11 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
E/flutter (11080): #12 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:94:7)
E/flutter (11080): #13 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
E/flutter (11080): #14 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter (11080): #15 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter (11080): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
E/flutter (11080): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
E/flutter (11080): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
E/flutter (11080): #19 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
E/flutter (11080): #20 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
E/flutter (11080): #21 _invoke1 (dart:ui/hooks.dart:134:13)
E/flutter (11080): #22 _dispatchPointerDataPacket (dart:ui/hooks.dart:91:5)
在CURL中尝试相同的请求对两种方法均适用:
final response = await http.get('http://192.168.1.94', headers: {"Accept": "*/*"},);
用于运行服务器的lua代码为:
I/flutter (15857): {
I/flutter (15857): "args": {},
I/flutter (15857): "headers": {
I/flutter (15857): "Accept": "*/*",
I/flutter (15857): "Accept-Encoding": "gzip",
I/flutter (15857): "Connection": "close",
I/flutter (15857): "Host": "httpbin.org",
I/flutter (15857): "User-Agent": "Dart/2.0 (dart:io)"
I/flutter (15857): },
I/flutter (15857): "origin": "89.69.232.252",
I/flutter (15857): "url": "https://httpbin.org/get"
I/flutter (15857): }
该服务器一直对我来说运行良好(在curl,wget和浏览器中),而Flutter中的get请求对于其他服务器也可以正常工作。只是两者的结合才有问题。
http package版本是0.11.3 + 17
[EDIT] 更多信息:
测试是在装有Android 4.1.18的Huawei P9 Lite手机上进行的。
Flutter构建环境(带有Android Studio)已完全更新。
通过笔记本电脑进行的CURL测试,还在笔记本电脑和手机上的浏览器中进行了测试。
所有设备(笔记本电脑,电话,服务器主板)都是同一路由器的直接客户端,具有静态IP。
答案 0 :(得分:0)
贷记到@augustzf(请参阅问题注释):
在未获得正确的HTTP响应时会慌乱,因此lua代码需要发送例如:
conn:send("HTTP/1.0 200/OK\r\nServer: tiny lua webserver\r\n")