I am trying to make post call as the code bellow shows.
Map<String, String> header = {"Content-Type": "application/json"};
Map<String, String> body = {
"client_id": "xxxx",
"client_secret": "XXXX",
"password": "password",
"username": "username",
};
Future<Post> callForFirstToken() async {
final response = await http.post(url, headers: header, body: body);
return response.statusCode == 200
? Post.fromJson(json.decode(response.body))
: throw Exception('Failed to load ...');}
But, I have got this error:
Error connecting to the service protocol: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:60556/sK_cPlYMcGQ=/ws
I have replaced the header to as bellow shows and works
{"HttpHeaders.contentTypeHeader": "application/json"}
I think I had the same issue, but I'm not sure how I solved.
I think it was adding this to the header: ..headers["Content-Type"] = "application/json"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With