http - Http请求为flutter web抛出XMLHttpRequest错误
问题描述
我正在使用 Flutter Web 创建一个 RSS 提要阅读器 Web 应用程序。此应用程序调用由不同提供商提供的公共 RSS 提要。
我正在使用 Http get 进行调用,它会引发XMLHttpRequest错误。
我无法得到任何回应。您能否让我知道如何解决此错误并获得回复?
例如:使用的 rss 提要是https://www.space.com/feeds/all
注意:在移动设备上进行相同测试时,它可以正常工作并提供响应。
谢谢
下面粘贴的是正在使用的代码
//Fetching the feed data for the given url
Future<List<FeedItemDetails>> fetchFeedItemList(String category, String url) async {
print("Calling URL : $url");
http.Response response = await http
.get(url)
.timeout(Duration(seconds: Constants.NETWORK_TIMEOUT_SECONDS));
if (response.statusCode == 200) {
List<FeedItemDetails> feedItemList = List<FeedItemDetails>();
switch (_getFeedType(response.body)) {
case Constants.FEED_TYPE_RSS:
{
//Parsing the RSS feed from the response
RssFeed rssFeed = RssFeed.parse(response.body);
//Keeping the image of feed for adding in FeedItemDetails,
String rssImageURL = rssFeed.image == null ? "" : rssFeed.image.url;
feedItemList = rssFeed.items
.map((item) => FeedItemDetails.parseRSSItem(item,category,rssImageURL))
.toList();
}
break;
case Constants.FEED_TYPE_ATOM:
{
//Parsing the RSS feed from the response
AtomFeed atomFeed = AtomFeed.parse(response.body);
//Keeping the logo of feed for adding in FeedItemDetails,
String atomImageURL = atomFeed.logo == null ? "" : atomFeed.logo;
feedItemList = atomFeed.items
.map(
(item) => FeedItemDetails.parseAtomItem(item,category, atomImageURL))
.toList();
}
break;
default:
{
throw Exception(Constants.INVALID_FEED_DATA);
}
}
return feedItemList;
} else {
// If service call was not successful, throw an error.
throw Exception(Constants.INVALID_RESPONSE);
}
}
解决方案
推荐阅读
- azure - Azure - 集中管理客户端机密
- java - Java ProcessBuilder问题——目录问题
- python - 从 32 升级到 fedora 33 后,dnf 不再工作
- javascript - 正则表达式在第三个斜杠之后但在减号之前获取第一个单词
- flutter - Flutter 自定义包不加载字体和图片 | 扑
- cmake - CMake 无法获取 Python3_SITELIB
- tags - Universal-ctags 可以在输出中生成一个标志,描述标签的种类吗?
- nginx - Nginx 和 uWSGI (13: Permission denied) 同时连接到上游
- python - 在自定义 django search_form 管理模板中获取当前路径
- android - 使用协程崩溃应用程序引发异常而不是处理失败