How to make an HTTP Request to In Flutter Web ?
You can use the features of Flutter, and you will not need a browser plug-in. So, in this article, we will go through how to make HTTP Request to In Flutter Web?
How to Make an HTTP Request to In Flutter Web?
In addition to mobile apps, Flutter supports the generation of web content rendered using standards-based web technologies: HTML, CSS, and JavaScript. With web support, you can compile existing Flutter code written in Dart into a client experience that can be embedded in the browser and deployed to any web server.
For Accessing a website made by flutter basically, you are calling a JS script. And for any website to give access to a script which in this case was another website you can access the API. You also need to give some sort of clearance to access.
In this case, it is CORS – Cross-Origin Resource Sharing.
Add the below code to your website.htaccess file
<ifModule mod_headers.c> SetEnvIf Origin "http(s)?://(www.)?(localhost:55538|somedomain.com)$" AccessControlAllowOrigin=$0 Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin Header always set Access-Control-Allow-Methods: "GET,POST,PUT,DELETE,OPTIONS" </ifModule>
Adding this will now grant access to your flutter website to hit requests to your APIs. To get it to “work” temporarily, you can launch Chrome with CORS turned off. Obviously, this is not a long-term solution, but it should get you going. The command you need is:
open /Applications/Google\ Chrome.app --args --disable-web-security --user-data-dir
Conclusion:
Thanks for being with us on a Flutter Journey!
So, in this article, we have seen how to make an HTTP Request to In Flutter Web. Also, feel free to comment and provide any other suggestions regarding Flutter.
Flutter Agency is our portal Platform dedicated to Flutter Technology and Flutter Developers. Also, the portal is full of cool resources from Flutter like Flutter Widget Guide, Flutter Projects, Code libs and etc.
Flutter Agency is one of the most popular online portals dedicated to Flutter Technology. Daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.