Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6184

DioException [bad response]: This exception was thrown because the response has a status code of 307

$
0
0

I am using flutter linux app to run some APIs that I wrote them with fast api running localling on my ubuntu machiene.APIs are working well when test them with postman but I am getting 307 error when call them at my flutter app.The error show 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/docs/Web/HTTP/StatusIn 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<bool> 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;    }  }}

I tried:dio.options.followRedirects = true;

I feel that I should change some settings on my machine!


Viewing all articles
Browse latest Browse all 6184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>