如何在http get请求中传递参数?

时间:2020-05-17 20:31:54

标签: flutter curl dart

我想在flutter应用程序的http get请求中传递参数。这是我要在http get请求中转换的代码cUrl代码。

enter image description here

这是我想要改善的代码

Future<http.Response> getTarget(String type, String q) async {
  try {
    final response = await dio.Dio().get(
      'https://graph.facebook.com/v2.11/search',
      queryParameters: {'type': type, 'q': q, 'access_token': ACCESS_TOKEN},
    );
  } catch (e) {
    print('Error: $e');
    print(e.code);
  }
}

1 个答案:

答案 0 :(得分:0)

您可以签出以下link(请参见示例部分)。

根据您的问题,您可以像以前一样在queryParameters中发送参数,也可以按如下所示在URL中传递它们:

Future<http.Response> getTarget(String type, String q) async {
  try {
    final response = await dio.Dio().get(
      "https://graph.facebook.com/v2.11/search?type=${type}&q=${q}&access_token=${ACCESS_TOKEN}"
    );
  } catch (e) {
    print('Error: $e');
    print(e.code);
  }
}