DEV Community

Henrique
Henrique

Posted on

403 error <Bad state: Cannot access the body fields of a Request without content-type "application/x-www-form-urlencoded".>

Calling an external api for user authentication and build a graphql client
Try to use request, with jsonEncode:

  final response = await http.post(
    url,
    headers: {
      "Content-type": 'application/x-www-form-urlencoded',
      "accept": "application/json",
    },
    body: jsonEncode({
      "username": username,
      "password": password,
      "plataforma": plataforma,
    }),
  );
Enter fullscreen mode Exit fullscreen mode

and, without jsonEncode

  final response = await http.post(
    url,
    headers: {
    'pragma': 'no-cache',
    'cache-control': 'no-cache',
    'cookie': 'signInPanel..signInForm..$username'
    },
    body: ({
      "username": username,
      "password": password,
      "plataforma": plataforma,
    }),
  );
Enter fullscreen mode Exit fullscreen mode

in both options, triggerd error
Apreciate some help.

Top comments (0)