Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 正在Get请求中发送标头_Flutter_Dart - Fatal编程技术网

Flutter 正在Get请求中发送标头

Flutter 正在Get请求中发送标头,flutter,dart,Flutter,Dart,我想发送一个获取请求请求。但我一直在找回HTML代码 在Postman中,我必须指定accept:application/json才能获取json。但是我正在学习的教程没有提到 下面是我的代码 void getData() async { http.Response response = await http.get( 'https://libriboo.com/api/landing'); // var res = json.decode(response.b

我想发送一个获取请求请求。但我一直在找回HTML代码

在Postman中,我必须指定
accept:application/json
才能获取json。但是我正在学习的教程没有提到

下面是我的代码

  void getData() async {
    http.Response response = await http.get(
        'https://libriboo.com/api/landing');
  //  var res = json.decode(response.body);
    print(response.body);
  }
我明白了

I/flutter ( 5134):   <head>
I/flutter ( 5134):     <title>Libri</title>
I/flutter ( 5134):     <!-- Required meta tags -->
I/flutter ( 5134):     <meta charset="utf-8">
I/flutter ( 5134):     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
I/flutter ( 5134):     <link rel="shortcut icon" type="image/png" href=".\images\favicon.png">
I/flutter ( 5134):     <!-- Bootstrap CSS -->
I/flutter ( 5134):     <link rel="stylesheet" href=".\assets\css\style.css">
I/flutter ( 5134):     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
I/flutter ( 5134):     <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
I/flutter ( 5134):     <link rel="stylesheet" href=".\assets\css\bootstrap.css">
I/flutter ( 5134):     <link rel="stylesheet" href=".\assets\css\font-awesome.css">
I/flutter ( 5134):     <script src="..\assets\js\script.js"></script>
I/flutter ( 5134): 
I/flutter ( 5134): 
I/flutter ( 5134): 
I/flutter ( 5134):   </head
I/颤振(5134):
I/颤振(5134):Libri
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/颤振(5134):
I/flatter(5134):您可以在
标题中指定
内容类型
,如下所示:

void getData() async {
    http.Response response = await http.get(
        'https://libriboo.com/api/landing',headers:{
        "Content-Type":"application/json"
    });
    print(response.body);
  }

似乎在请求过程中出现了服务器端错误,请尝试打印statusCode或像这样尝试

void getData() async {
    http.Response response = await http.get(
        'https://libriboo.com/api/landing', 
        headers:{ "Content-Type":"application/json"}
      );
  print(response.statusCode);
    //  var res = json.decode(response.body);
    // print(response.body);
}