I have a login page where i am trying to send a login request to my backend. But I get an Unhandled Exception: Invalid header field name. Here is my submit function
submit() async {
var res = await LoginAPI().loginData(
{'email': _emailController.value, 'password': _passwordController.value});
var body = json.decode(res.body);
print(body);
}
Then in my LoginAPI class here is my loginData function that makes the call to the backend
import 'dart:convert';
import 'package:http/http.dart' as http;
class LoginAPI {
final String _url = "http://10.0.2.2:8000/api/";
Map<String, String> headers = {"Content-type": "application/json"};
loginData(data) async {
var fullUrl = _url + "v1/users/login";
return await http.post(
fullUrl,
body: jsonEncode(data),
headers: headers
);
}
}
Here is my request through postman

Here is my response through postman

When I make the same request with Postman i get the response I am supposed to get. What Am i doing wrong?

package:httplower cases all header names, which is perfectly valid but confuses some servers. Confirm with another client (not sure if you can control the header name in postman) with a lower casecontent-type. If you can duplicate the problem, then it's a server issue. You can always just use Dart'sHttpClientwhich does not change the case of headers.