title: flutter http get - why do I get "Invalid request method" when accessing a server running on NodeMCU?
body: <p>When I try to make a request from a Flutter app to a server running on NodeMCU (microcontroller with Lua), I get the following error:</p>
  
  <pre><code>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): &lt;asynchronous suspension&gt;
  E/flutter (11080): #1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:171:38)
  E/flutter (11080): &lt;asynchronous suspension&gt;
  E/flutter (11080): #2      BaseClient.get (package:http/src/base_client.dart:34:5)
  E/flutter (11080): #3      get.&lt;anonymous closure&gt; (package:http/http.dart:47:34)
  E/flutter (11080): #4      _withClient (package:http/http.dart:167:20)
  E/flutter (11080): &lt;asynchronous suspension&gt;
  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): &lt;asynchronous suspension&gt;
  E/flutter (11080): #7      _MyHomePageState.build.&lt;anonymous closure&gt; (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.&lt;anonymous closure&gt; (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&amp;BindingBase&amp;GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
  E/flutter (11080): #17     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
  E/flutter (11080): #18     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
  E/flutter (11080): #19     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
  E/flutter (11080): #20     _WidgetsFlutterBinding&amp;BindingBase&amp;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)
  </code></pre>
  
  <p>The line this happens on is:</p>
  
  <pre><code>final response = await http.get('http://192.168.1.94', headers: {"Accept": "*/*"},);
  </code></pre>
  
  <p>The 'Accept' header makes no difference.<br>
  If instead I direct it to any other URL (e.g. "<a href="https://httpbin.org/get" rel="nofollow noreferrer">https://httpbin.org/get</a>"), the request is performed correctly:</p>
  
  <pre><code>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): }
  </code></pre>
  
  <p>Trying the same request in CURL works for both:</p>
  
  <pre><code>$ curl -X GET "https://httpbin.org/get" -H  "Accept-Encoding: gzip" -H  "User-Agent: Dart/2.0 (dart:io)" -H  "Connection: close"
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                   Dload  Upload   Total   Spent    Left  Speed
  100   254  100   254    0     0     96      0  0:00:02  0:00:02 --:--:--    96{
    "args": {},
    "headers": {
      "Accept": "*/*",
      "Accept-Encoding": "gzip",
      "Connection": "close",
      "Host": "httpbin.org",
      "User-Agent": "Dart/2.0 (dart:io)"
    },
    "origin": "89.69.232.252",
    "url": "https://httpbin.org/get"
  }
  
  $ curl -X GET "http://192.168.1.94" -H  "Accept-Encoding: gzip" -H  "User-Agent: Dart/2.0 (dart:io)" -H  "Connection: close"
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                   Dload  Upload   Total   Spent    Left  Speed
  100    11    0    11    0     0     47      0 --:--:-- --:--:-- --:--:--    47{"empty":1}
  </code></pre>
  
  <p>The lua code for running the server is:</p>
  
  <pre><code>function serve(conn, payload)
      conn:send("{\"empty\":1}")
      conn:close()
  end
  
  srv=net.createServer(net.TCP)
  srv:listen(80, function(conn)
      conn:on("receive",function(conn,payload)
          serve(conn, payload)
          collectgarbage()
      end) 
  end)
  </code></pre>
  
  <p>The server has always worked well for me (in curl, wget, and browsers) and the get request in Flutter works fine for other servers. It's only the combination of the two that has a problem.<br>
  The <a href="https://pub.dartlang.org/packages/http" rel="nofollow noreferrer">http package</a> version is 0.11.3+17</p>
  
  <p><strong>[EDIT]</strong> more info:<br>
  testing was done on a Huawei P9 Lite phone with Android 4.1.18.<br>
  Flutter build environment (w/ Android Studio) fully updated.<br>
  CURL testing done from laptop, tested also in browser both on laptop and on phone.<br>
  All devices (laptop, phone, server board) are direct clients of the same router, with static IPs.</p>