简体   繁体   English

无法使用 flutter 向我的 api 发送发布请求

[英]Cant send a post request to my api with flutter

I am trying to make a post request to my api to create a new user.我正在尝试向我的 api 发出发布请求以创建新用户。 My api works and I tried everything that I could find.我的 api 工作正常,我尝试了所有我能找到的东西。 The output is: Unhandled Exception: Bad state: Insecure HTTP is not allowed by platform: http://10.0.2.2:5000/api/register The output is: Unhandled Exception: Bad state: Insecure HTTP is not allowed by platform: http://10.0.2.2:5000/api/register

I am using an android emulator I tried to use on my android phone it didn't work...我正在使用一个 android 仿真器,我试图在我的 android 手机上使用它没有工作......

If you want to allow HTTP request (it's by default disabled), you have to add this code in application tag in android manifest file:如果您想允许 HTTP 请求(默认禁用),您必须在 android 清单文件的应用程序标签中添加此代码:

<application android:usesCleartextTraffic="true"/>

and for iOS view info.plist as source code and add this code:对于 iOS 查看 info.plist 作为源代码并添加以下代码:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

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

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