flutterでrailsのdevise token authに新規登録にリクエストを投げたところ、タイトルのエラーが発生
pry-remoteで確認したところ中身がなかったので、flutterの方に問題がある可能性
1 2 | [1] pry(#<Api::Auth::RegistrationsController>)> params => <ActionController::Parameters {"controller"=>"api/auth/registrations", "action"=>"create"} permitted: false> |
flutterは
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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がないので追加してみます
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // 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を追加したところ、リクエストが通りました!