扑来 - 我可以向EC2集成环境端点提出请求

发布于 2025-02-13 09:21:31 字数 1360 浏览 1 评论 0原文

我无法通过颤动向AWS实例端点提出请求。随着代码在请求中停止时,下面的行甚至都没有执行。

Future getCode() async {
  Response response = await client.get(
    Uri.parse('http://ec2-54-202-27-94.sa-east-1.compute.amazonaws.com/test/api/v1/example'),
  );

  print(response.statusCode);
}

我能够通过Postman执行相同的请求。

但是,当我通过颤动向相同端点提出请求,更改域的第一部分(提出生产环境而不是对同类的要求)时,它有效:

集成URL(不起作用)

http://ec2-54-202-27-94.sa-east-1.compute.amazonaws.com/test/api/v1/example

http://www.test.com/test.com/test/api/api/api/api/v1/example

我还强调,集成环境是生产环境的副本,应该可以访问两者。

我相信,没有必要对接收这些请求的服务器进行任何更改,因为我可以通过Postman成功提出请求。

我如何通过颤音提出此请求

示例请求网站的请求URL

I can't make a request to an AWS instance endpoint through Flutter. The line below is not even executed, as the code stops on the request.

Future getCode() async {
  Response response = await client.get(
    Uri.parse('http://ec2-54-202-27-94.sa-east-1.compute.amazonaws.com/test/api/v1/example'),
  );

  print(response.statusCode);
}

I am able to perform this same request through Postman.

However, when I make a request via Flutter to the same endpoint, changing the first part of the domain (making the request for the Production environment and not for Homologation), it works:

Integration URL (does not work in Flutter)

http://ec2-54-202-27-94.sa-east-1.compute.amazonaws.com/test/api/v1/example

Production URL (works in Flutter)

http://www.test.com/test/api/v1/example

I also emphasize that the integration environment is a copy of the production environment, which should allow access to both.

I believe that it is not necessary to make any changes to the server that receives these requests, as I can successfully make the request through Postman.

How can I make this request through Flutter?

Sample request URL for production environment
enter image description here

Sample request URL for homologation environment
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟若柳尘 2025-02-20 09:21:31

它可以通过调用集成环境的端池来工作,

为此,它有必要使用BadCertificateCallback并指定我想允许访问的证书。我创建了一个指定此内容的类:

class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext context) {
    return super.createHttpClient(context)
      ..badCertificateCallback = (X509Certificate cert, String host, int port) {
        if (host.isNotEmpty &&
            host == 'ec2-54-202-27-94.sa-east-1.compute.amazonaws.com') {
          return true;
        } else {
          return false;
        }
      };
  }
}

添加以下行

WidgetsFlutterBinding.ensureInitialized();
HttpOverrides.global = MyHttpOverrides();

在具有主函数的项目文件中,以这种方式

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  HttpOverrides.global = MyHttpOverrides();

    runApp(
      MyApp(),
    );
}

:不适合在生产环境中使用不安全的证书。仅在调试模式下使用

It worked for the request to work by calling the endpont of the integration environment

For this it was necessary to use the badCertificateCallback and specify the certificate that I would like to allow access. I created a class specifying this:

class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext context) {
    return super.createHttpClient(context)
      ..badCertificateCallback = (X509Certificate cert, String host, int port) {
        if (host.isNotEmpty &&
            host == 'ec2-54-202-27-94.sa-east-1.compute.amazonaws.com') {
          return true;
        } else {
          return false;
        }
      };
  }
}

And in the project file that has the main function, add the following lines

WidgetsFlutterBinding.ensureInitialized();
HttpOverrides.global = MyHttpOverrides();

This way:

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  HttpOverrides.global = MyHttpOverrides();

    runApp(
      MyApp(),
    );
}

It is not appropriate to allow the use of insecure certificates in a production environment. Use only in Debug mode

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文