首页 > 解决方案 > FormatException:意外字符(在字符 1 处) - firebase 身份验证

问题描述

I/flutter ( 4737): FormatException: Unexpected character (at character 1)
I/flutter ( 4737): <!DOCTYPE html>
I/flutter ( 4737): ^

这是我得到的完整错误。这是我发出帖子请求的代码部分。请注意,这CustomExeption是我自己的错误,我正在我的应用程序的其他部分处理它。

Future<void> signup(String email, String password) async {
    final url =
        "https://identitytoolkit.googleapis.com/v1/accounts:SignUp?key=[API_KEY]";
    try {
      final response = await http.post(
        url,
        body: json.encode(
          {
            "email": email,
            "password": password,
            "returnSecureToken": true,
          },
        ),
      );
      if (json.decode(response.body)['error'] != null) {
        throw CustomException(
          json.decode(response.body)['error']['message'],
        );
      }
    } catch (error) {
      throw error;//Han
    }
  }

这是触发上述方法的代码部分

  Future<void> _saveForm() async {
    if (!_form.currentState.validate()) {
      return;
    }
    if (_isSubmitted == false) {
      await Provider.of<Auth>(
        context,
        listen: false,
      ).signup(
        _new_user.getEmail,
        _new_user.getPass,
      );
      setState(() {
        _isSubmitted = true;
      });
    }
}

请让我知道如何进行。在此先感谢!

标签: firebaseflutterfirebase-authentication

解决方案


推荐阅读