DioException [неправильный ответ]: это исключение было создано, поскольку ответ имеет код состояния 307. ⇐ Python
DioException [неправильный ответ]: это исключение было создано, поскольку ответ имеет код состояния 307.
I am using Flutter Linux app to run some APIs that I wrote with fast APIs running locally on my Ubuntu machine. APIs are working well when tested with Postman, but I am getting a 307 error when calling them in my Flutter app. The error shows that I should fix my code, but I have no idea!
flutter: Error during registration: DioException [bad response]: This exception was thrown because the response has a status code of 307 and RequestOptions.validateStatus was configured to throw for this status code. The status code of 307 has the following meaning: "Redirection: further action needs to be taken in order to complete the request" Read more about status codes at https://developer.mozilla.org/en-US/doc ... TTP/Status In order to resolve this exception you typically have either to verify and fix your request code or you have to fix the server code. here is my flutter auth code
class AuthApi{ StorageManager storageManager =StorageManager(); AppInterceptor appInterceptor = AppInterceptor(); String authMsg = ''; final Dio _dio = Dio(); Future login(String email, String password) async { try { Response response = await _dio.post(APIs.tokenEndpoint, data: { "email": email, "password": password}, options: Options(headers: {'Content-Type': 'application/json',}), ); print(response.data); if(response.statusCode == 200 || response.statusCode ==201){ var dataObj = LoginResponse.fromJson(response.data); print(dataObj.email); if (dataObj.token == null || dataObj.token == "") { debugPrint("token is null"); return false; } storageManager.saveAccessToken(dataObj.token); storageManager.saveUserRole(dataObj.role); return true; }else{ var data = jsonDecode(response.data); authMsg = data["detail"]; return false; } } catch (e) { return false; } } } change dio into http package resulted in the same error
flutter: Registration failed with status: 307 postman testing: https://drive.google.com/file/d/1-3BxTg ... sp=sharing
I tried: dio.options.followRedirects = true;
I feel that I should change some settings on my machine!
Источник: https://stackoverflow.com/questions/780 ... sponse-has
I am using Flutter Linux app to run some APIs that I wrote with fast APIs running locally on my Ubuntu machine. APIs are working well when tested with Postman, but I am getting a 307 error when calling them in my Flutter app. The error shows that I should fix my code, but I have no idea!
flutter: Error during registration: DioException [bad response]: This exception was thrown because the response has a status code of 307 and RequestOptions.validateStatus was configured to throw for this status code. The status code of 307 has the following meaning: "Redirection: further action needs to be taken in order to complete the request" Read more about status codes at https://developer.mozilla.org/en-US/doc ... TTP/Status In order to resolve this exception you typically have either to verify and fix your request code or you have to fix the server code. here is my flutter auth code
class AuthApi{ StorageManager storageManager =StorageManager(); AppInterceptor appInterceptor = AppInterceptor(); String authMsg = ''; final Dio _dio = Dio(); Future login(String email, String password) async { try { Response response = await _dio.post(APIs.tokenEndpoint, data: { "email": email, "password": password}, options: Options(headers: {'Content-Type': 'application/json',}), ); print(response.data); if(response.statusCode == 200 || response.statusCode ==201){ var dataObj = LoginResponse.fromJson(response.data); print(dataObj.email); if (dataObj.token == null || dataObj.token == "") { debugPrint("token is null"); return false; } storageManager.saveAccessToken(dataObj.token); storageManager.saveUserRole(dataObj.role); return true; }else{ var data = jsonDecode(response.data); authMsg = data["detail"]; return false; } } catch (e) { return false; } } } change dio into http package resulted in the same error
flutter: Registration failed with status: 307 postman testing: https://drive.google.com/file/d/1-3BxTg ... sp=sharing
I tried: dio.options.followRedirects = true;
I feel that I should change some settings on my machine!
Источник: https://stackoverflow.com/questions/780 ... sponse-has
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение