【发布时间】:2019-10-06 02:58:00
【问题描述】:
我正在尝试在我的 Flutter Web 应用程序中向 000webhost 发出 HTTP 请求,如下所示。第一种方法和第二种方法一样,我只是改变了网址。但是,第一个有效,但第二个无效。有人建议添加更多标题,但我不知道要添加哪些标题。
// This method WORKS
getMethod()async{
print("IN GET ....");
String theUrl = 'https://jsonplaceholder.typicode.com/todos';
var res = await http.Client().get(Uri.encodeFull(theUrl),headers: {"Accept":"application/json"});
//var res = await http.get(Uri.encodeFull(theUrl),headers: {"Accept":"application/json"});
var responsBody = json.decode(res.body);
print(responsBody);
return responsBody;
}
// This DOES NOT WORK
getMethod()async{
print("IN GET ....");
String theUrl = 'https://funholidayshotels.000webhostapp.com/fetchData.php';
var res = await http.Client().get(Uri.encodeFull(theUrl),headers: {"Accept":"application/json"});
//var res = await http.get(Uri.encodeFull(theUrl),headers: {"Accept":"application/json"});
var responsBody = json.decode(res.body);
print(responsBody);
return responsBody;
}
【问题讨论】:
-
问题的框架很好。在回答这个问题之前,我认为这是颤振包的一些问题。这个问题促使我对后端进行更改。
标签: dart flutter flutter-web hummingbird