title: flutter error 403 in post request using dio
body: <p>i have a problem with hate. I'm trying to login using dio, the login method works perfectly, but when I put invalid credentials dio gives me this error:</p>
  <p><a href="https://i.stack.imgur.com/ngbvm.png" rel="nofollow noreferrer">DioError</a></p>
  <p><a href="https://i.stack.imgur.com/ubpv6.png" rel="nofollow noreferrer">Error in execution</a></p>
  <p>I created a boolean function that would return true or false if the statuscode was 200 it would return true and if not it would return false, but when logging in with the right credentials everything is ok, everything happens as it should, but when logging in with invalid credentials this error above causes it. I'm using shared preferences to store the tolken in the app, and the logic would be simple, if it was 200 I would log into the app, otherwise it would show me a snackbar I made in another file, this is my code:</p>
  <pre><code>loginFinal() async {
      if (formKey.currentState!.validate()) {
        bool loginIsOk = await loginConect();
        if (loginIsOk) {
          Get.offAllNamed(&quot;/home&quot;);
          await Future.delayed(const Duration(seconds: 1));
          message(MessageModel.info(
            title: &quot;Sucesso&quot;,
            message: &quot;Seja bem vindo(a) influenciador(a)&quot;,
          ));
        } else {
          loaderRx(false); //LOADER
          message(MessageModel.error(
            title: &quot;Erro&quot;,
            message: &quot;Erro ao realizar login&quot;,
          ));
        }
      }
    }
  
    //LOGICA DE ENTRAR NO APP
  
    Future&lt;bool&gt; loginConect() async {
      final dio = Dio();
      String baseUrl = &quot;https://soller-api-staging.herokuapp.com&quot;;
  
      loaderRx(true); //LOADER
  
      SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
  
      final response = await dio.post(
        baseUrl + &quot;/auth&quot;,
        data: jsonEncode(
          {
            &quot;login&quot;: emailController.text,
            &quot;senha&quot;: passWordController.text,
          },
        ),
        options: Options(
          headers: {'Content-Type': 'application/json; charset=UTF-8'},
          method: &quot;post&quot;,
        ),
      );
      if (response.statusCode == 200) {
        await sharedPreferences.setString(
          &quot;token&quot;,
          &quot;string: ${response.data[&quot;string&quot;]}&quot;,
        );
        print(&quot;Resposta: ${response.data[&quot;string&quot;]}&quot;);
  
        loaderRx(false);
  
        return true;
      } else {
        print(&quot;RESPOSTA: ${response.data}&quot;);
  
        return false;
      }
      
    }
  }
  </code></pre>