flutter-plugins icon indicating copy to clipboard operation
flutter-plugins copied to clipboard

Does not send HTTP requests in Linux

Open roboticafacil opened this issue 1 year ago • 0 comments

I have created an App (in Windows and Linux) that on the one side creates a web service listenning to HTTP requests on port 4000. That part is working find since I have check on a web browser also using curl that the service responds to requests. It also works from a specific web-page I have created sending HTTP using "fetch" in javascript each time a press a button when that web page is accessed via a web-browser (i.e.: firefox).

Now, I want to develop another app (or even in the same app that's not relevant) that uses desktop_webview_window plugin to open the web-page before mentioned. In Windows, it works as expected, I am able to receive HTTP request on the web service side. But if I run the same flutter code in Linux (Ubuntu 22.04), the web service does not receive any request (no print is reported in the console). Indeed, I have monitored the traffic on the specific port when I sue the desktop_webivew_window pluging and nothing is even sent from the plugin to the web service, so tcpdump reports no HTTP traffic at that specific port and interface.

Reproduce Steps

The web service is created using shelf_io:

Future<HttpServer> createServer(){ final headers = { 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json;' }; var handler = const Pipeline().addMiddleware(corsHeaders(headers: headers)).addHandler(clientRequest); return shelf_io.serve(handler, 'localhost', 4000); }

Future<Response> clientRequest(Request request) async { String path = request.url.path; debugPrint(path); return Response.ok(jsonEncode({"result": "OK"})); }

While the webview is lauched as:

final webview= await WebviewWindow.create(configuration: CreateConfiguration( windowHeight: window.physicalSize.height.toInt(), windowWidth: window.physicalSize.width.toInt(), title: title)); webview.launch(url);

In the web page with the URL indicated in the lauch method I have a javascript code that basically sends the HTTP to the web service by:

var url='http://localhost:4000'; const response = await fetch(url, {method: 'POST',headers: {'Content-Type': 'application/json'},body: {}}); const r = await response.json(); console.log(r);

Version (please complete the following information):

  • Flutter Version: [e.g. v3.16.3]
  • OS: [e.g. Windows/Linux]
  • plugin: [e.g. desktop_webview_window: 0.2.1]

roboticafacil avatar Dec 14 '23 15:12 roboticafacil