【问题标题】:API access issue in FlutterFlutter 中的 API 访问问题
【发布时间】:2020-06-07 23:06:21
【问题描述】:

我正在尝试在 API 上发出 GET 请求,但它给出了 error 400 尽管我尝试了所有方法,但如果我尝试使用 postman 使用类似的 URL 和 auth_key,它会获得所需的输出。 我认为这可能是某些主机的问题,因为在邮递员中主机也存在于标题中。

Future<String> getJsonData() async{

    var response = await http.get(
      Uri.encodeFull(url),
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'ApiKey'}
    );

    if(response.statusCode != 200){
      return "failed";
    }

    setState((){
      var convertData = json.decode(response.body);
      var temp = convertData["objects"] as List;

      data = temp.map<Detail>((json) => Detail.fromJson(json)).toList();
    });

    print(data.length);
    return "Success";
}

【问题讨论】:

    标签: http flutter dart


    【解决方案1】:

    你应该检查它'Authorization': 'ApiKey' 你必须给一个字符串 key 而不是字符串 "ApiKey"

    【讨论】:

    • 是的,我只添加了实际的 api 密钥。
    猜你喜欢
    • 2022-08-06
    • 2021-10-11
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 2022-01-19
    相关资源
    最近更新 更多