R
Railway16mo ago
anlat_

Server returns a 400 Bad Request error.

Hi, I have an issue with the registration endpoint on my Railway server. When I attempt to register a new user using the Flutter app with the Django rest api, the server returns a 400 Bad Request error, despite a successful registration. I have checked the Django and flutter codes and I cannot find any errors that would explain why the registration endpoint is returning a 400 Bad Request error. I have also tried registering a new user using the Djangofrom the web, and I am able to register the user successfully wıthout any error .I believe that the issue is with the server configuration. I would like to request your assistance in debugging this issue. Thank you for your time and attention.
5 Replies
Percy
Percy16mo ago
Please provide your project ID or reply with N/A. Thread will automatically be closed if no reply is received within 10 minutes. You can copy your project's id by pressing Ctrl/Cmd + K -> Copy Project ID.
Brody
Brody16mo ago
please show me the code that makes the request @anlat_
anlat_
anlat_OP16mo ago
If you dont mind I will sent it a few hours letter. I just left my flat. tnx flutter main.dart Future<void> _register() async { try { final response = await http.post( Uri.parse('https://wk.up.railway.app/dj-rest-auth/registration/'), headers: <String, String>{ 'Content-Type': 'application/json; charset=UTF-8', }, body: jsonEncode(<String, String>{ 'username': _usernameController.text, 'email': _emailController.text, 'password1': _passwordController.text, 'password2': _confirmPasswordController.text, }), ); if (response.statusCode == 201) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text('Registration successful!'), backgroundColor: Colors.green, )); // Navigate to Home Page after a short delay to let the SnackBar show Future.delayed(Duration(seconds: 2), () { Navigator.pop(context); }); } else { print('Response body: ${response.body}'); if (response.body.isNotEmpty) { // Only attempt to decode if the body is not empty Map<String, dynamic> responseBody = json.decode(response.body); String error = responseBody.values.first[0]; throw Exception(error); } else { throw Exception('Registration failed without a specific reason.');        }       }
Brody
Brody16mo ago
I'm not a flutter or python developer, so nothing jumps out as wrong to me, but I've been using railway long enough to know this isn't an issue with the platform, but an issue with your code or flutter app, I wish I could tell you the issue, but i don't know 😦
anlat_
anlat_OP16mo ago
OK. thanks I wonder about how I can view every http POST, GET commands in the railway app. In doing so, I might be able to pinpoint what's going wrong.
Want results from more Discord servers?
Add your server