簡體   English   中英

如何使用 Flutter 中的此格式從 API 獲取數據

[英]How To Fetch Data From API With This Format In Flutter

端點 - https://data.geoiq.io/dataapis/v1.0/covid/locationcheck

{“鍵”:字符串,“緯度”:數組}

[在此處輸入圖片描述][1]

如何使用 Flutter [1]: https://i.stack.imgur.com/V6hVH.png格式從 API 獲取數據

基本上,您的 API 端點正在請求正文。
在 flutter 中,可以使用 package http: ^0.12.1

import 'package:http/http.dart' as http;

final api = 'https://data.geoiq.io/dataapis/v1.0/covid/locationcheck';
final response = http.post(api, body: { "key": string, "latlngs": array });

如果 API 端點需要身份驗證令牌。 例如 Bearer token 然后你可以使用

final token = 'YOUR TOKEN';

final response = http.post(api, body: { "key": string, "latlngs": array }, headers: {
  'Authorization': 'Bearer $token',
});

請在下面找到示例請求。

import json as js
import requests
body =    {"latlngs": [
            [
                12.967444,
                77.498775

            ],
            [
                14.656773,
                77.627936
            ],
            [
                19.200027,
                72.970519
            ],
            [
                12.962882,
                77.543543
            ]],
        "key": "Auth Key"} 
headers = {'Content-Type': 'application/json'}
r = requests.post(url = "https://data.geoiq.io/dataapis/v1.0/covid/locationcheck", data = js.dumps(body), headers = headers)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM