当我查询 Postman 时,我得到状态为 200 的响应,但在 Flutter 中我得到 404,为什么?

问题描述 投票:0回答:0

当我查询Postman时,我得到状态为200且数据正确的响应,但在我的代码中我得到404响应。服务器不是我的,是我国的一家知名银行,所以服务器应该可以正常工作。帮助我的代码,我不明白为什么我得到404。我确信我在 Postman 和 Flutter 代码中写入相同的数据。

我尝试通过http包,但同样的错误。

我的颤振代码:

Future<void> getOrders() async {
  var dio = Dio();

  var url =
      'https://kaspi.kz/shop/api/v2/orders?filter[orders][code]=274556253';

  try {
    var response = await dio.get(
      url,
      options: Options(
        headers: {
          'Content-Type': 'application/vnd.api+json',
          'X-Auth-Token': '<my token (i have correct token!)>',
        },
      ),
    );

    if (response.statusCode == 200) {
      print('Response data: ${response.data}');
    } else {
      print('Request failed with status: ${response.statusCode}.');
    }
  } catch (e) {
    print('Error: $e');
  }
}
android flutter dart http http-status-code-404
© www.soinside.com 2019 - 2024. All rights reserved.