我正在使用flutter通过rest api从wordpress获取帖子,但我想对所有人禁用rest api,但通过Authentication启用
感谢进阶
我的代码:
Future<List<Posts>> fetchPosts() async {
List<Posts> posts = new List();
url = 'https://******.org/wp-json/wp/v2/posts?_compact&page=$page';
final response =
await http.get(url, headers: {"Accept": 'application/json'});
if (response.statusCode == 200 && _morePages == true) {
if (mounted == true) {
setState(() {
var jsonData = json.decode(response.body);
for (var p in jsonData) {
Posts post = Posts(
id: p['id'],
date: p['date'],
title: p['title'],
link: p['link'],
postViews: p['views'],
featuredImage: p['featured_image'],
featuredImageBig: p['featured_image_big'],
categories: p['categories'],
comments: p['comments'],
content: p['content'],
);
posts.add(post);
}
});
}