Flutter - Handle status code 302 in POST request

前端 未结 4 532
野性不改
野性不改 2020-12-19 10:07

I\'m trying to send a post request in Flutter with DIO package.

Here is the request:

getSessionId() async {

  var csrf =          


        
4条回答
  •  遥遥无期
    2020-12-19 11:12

    I solved this way:

    Add followRedirects: false and validateStatus: (status) { return status < 500;} to the request. Like this:

    var response = await Dio().post("http://myurl",
        data: requestBody,
        options: Options(
            followRedirects: false,
            validateStatus: (status) { return status < 500; }
        ),
    );
    

    This way you can get from the 302 every headers and other.

提交回复
热议问题