**
**curl -位置-请求发布'http://testing.thedivor.com/api/API/GetDistance‘-标题’内容-类型: application/json‘-数据-原始的{ "id":“id”:"placeid":“"EiBMZXdpc2hhbSBXYXksIExvbmRvbiBTRTQgMVVZLCBVSyIuKiwKFAoSCXk1YsdYAnZIERCJXqRiE8WPEhQKEgnrjwApXwJ2SBH76fXJO6C02w","”address":"Lewisham Way,London SE4 1 UK,UK",“邮政编码”:"SE4 1 UK“,"outcode":"SE4 1 UK”,“SE4 1 UK”:51.4702816,"country":"United UK“,"city":”city“,“经度”:-0.029187800000045172 },{ "_id":"null","placeid":“,”,“地址”:"Kenley,SW19 3DW,UK",“邮政编码”:"SE23 3RF","outcode":"SE23",“延迟”:"51.404556","country":"","",“城市”:"",“经度”:"-0.194486“} '‘}
颤振程序
'''var req = await Requests.post('http://testing.thedivor.com/api/API/GetDistance?', headers: {
'Content-Type' : 'application/json'
}, 身体: body // json对象);
print(req.json());
print(req.content().length);'''发布于 2021-03-03 09:54:04

试试这个:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
home: HomePage(),
),
);
}
class HomePage extends HookWidget {
Future<String> _getDistance() async {
final response = await http.post(
'http://testing.thedivor.com/api/API/GetDistance',
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(params),
);
print(response.body);
return response.statusCode == 200
? jsonDecode(response.body).toString()
: 'Failed to get distance';
}
@override
Widget build(BuildContext context) {
final _distance = useState<String>('');
useEffect(() {
_getDistance().then((d) => _distance.value = d);
return;
}, []);
return Scaffold(
body: Center(
child: Text(_distance.value),
),
);
}
}
final List<Map<String, dynamic>> params = [
{
"id": "",
"placeid":
"EiBMZXdpc2hhbSBXYXksIExvbmRvbiBTRTQgMVVZLCBVSyIuKiwKFAoSCXk1YsdYAnZIERCJXqRiE8WPEhQKEgnrjwApXwJ2SBH76fXJO6C02w",
"address": "Lewisham Way, London SE4 1UY, UK",
"postcode": "SE4 1UY",
"outcode": "SE4 1UY",
"lattitude": 51.4702816,
"country": "United Kingdom",
"city": "Greater London",
"longitude": -0.029187800000045172,
},
{
"_id": "null",
"placeid": "",
"address": "Kenley Road, London SW19 3DW, UK",
"postcode": "SE23 3RF",
"outcode": "SE23",
"lattitude": "51.404556",
"country": "",
"city": "",
"longitude": "-0.194486",
},
];https://stackoverflow.com/questions/66454089
复制相似问题