I am looking for a way to be able to send a GET HTTP request form Json style in dart. Everywhere I find that people had problems with the POST but no document about the GET. the issue is that if I write http.get(Uri.parse(uri)) I can't put the body: (where the form would go). it only lets me write body when it is a POST. i want to be able to run the next code with GET. The Uri.parse (i dont know why, but its the only way that allow me to get de URL)
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert' as convert;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
postTest() async {
final uri = 'http://10.0.2.2:5000/qna/';
http.Response response = await http.post(Uri.parse(uri), body: {
'pregunta': 'contacto',
});
print(response.body);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter WebView '),
),
body: Container(
child: TextButton(onPressed: postTest, child: Text('Push me')),
),
),
);
}
}