简体   繁体   English

如何通过 HTTP 请求将 Flutter 应用程序连接到 AWS EC2 实例

[英]How to connect flutter app to AWS EC2 Instance via HTTP request

I setup an EC2 instance and I Have been able to setup Apache, Mysql and PHPmyadmin on the server, I have also been able to create a php file that returns a JSON response from the items i have in a Mysql Database, when I access the public ip address of the EC2 instance, I can view the JSON response I returned from the PHP script (myipadress/get.php).我设置了一个 EC2 实例,并且已经能够在服务器上设置 Apache、Mysql 和 PHPmyadmin,我还能够创建一个 php 文件,该文件从我在 Mysql 数据库中的项目返回 JSON 响应,当我访问EC2实例的公共ip地址,我可以查看我从PHP脚本(myipadress/get.php)返回的JSON响应。 The issue I have right now is that when I try to make an HTTP request using the flutter Http package, i get the error message below我现在遇到的问题是,当我尝试使用 flutter Http 包发出 HTTP 请求时,我收到以下错误消息

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = myipadress, port = 41038

I believe this error might have to do with my AWS EC2 instance ports, but i can't seem to find a way to fix this.我相信此错误可能与我的 AWS EC2 实例端口有关,但我似乎找不到解决此问题的方法。

I guess the problem was not with the AWS EC2 Instance, the issue was as a result of the way I made the http request.我想问题不在于 AWS EC2 实例,问题在于我发出 http 请求的方式。

Below is the URI i was parsing into the request.下面是我解析到请求中的 URI。

final uri = Uri.https('myIpAdress', '/get.php');

I solved the problem by switching it to the code below, was formerly using https then switched to http.我通过将其切换到下面的代码解决了这个问题,以前使用 https 然后切换到 http。

final uri = Uri.http('myIpAdress', '/get.php');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM