flutterでrailsのdevise token authに新規登録にリクエストを投げたところ、タイトルのエラーが発生

pry-remoteで確認したところ中身がなかったので、flutterの方に問題がある可能性

[1] pry(#<Api::Auth::RegistrationsController>)> params
=> <ActionController::Parameters {"controller"=>"api/auth/registrations", "action"=>"create"} permitted: false>

flutterは

final url = 'http://10.0.2.2:3001/api/auth';
    try {
      final response = await http.post(url,
        body: json.encode(
          {
            'name': 'masahiro',
            'email': email,
            'password': password,
            'password_confirmation': password,
          },
        ),
      );
.....

headersがないので追加してみます

// flutterのコード
 final response = await http.post(url,
        headers: {'Content-Type': 'application/json'},
        body: json.encode(
          {
            'name': 'masahiro',
            'email': email,
            'password': password,
            'password_confirmation': password,
//            'returnSecureToken': true,
          },
        ),
      );

// railsのコンソール
[1] pry(#<Api::Auth::RegistrationsController>)> params
=> <ActionController::Parameters {"name"=>"masahiro", "email"=>"stmhamachiii@gmail.com", "password"=>"11111111", "password_confirmation"=>"11111111", "controller"=>"api/auth/registrations", "action"=>"create", "registration"=>{"name"=>"masahiro", "email"=>"stmhamachiii@gmail.com", "password"=>"11111111", "password_confirmation"=>"11111111"}} permitted: false>
[2] pry(#<Api::Auth::RegistrationsController>)> 

headersを追加したところ、リクエストが通りました!

参考記事

HTTP POST with Json on Body – Flutter/Dart

コメントをどうぞ

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA