Flutter-如何在POST请求中处理状态代码302?

时间:2019-11-17 10:41:29

标签: http post flutter dart

我正在尝试从POST请求中获取JSON响应(JSON格式的打入和打孔详细信息),但我得到的只是重定向302错误,并且请求中没有位置标头。

import 'package:http/http.dart' as http;
import 'package:dotp/dotp.dart';

void main() async {

  var client = http.Client();

  var login_url = 'https://test.site.com/index.php/index/loginpopupsave';
  var login_response = await client.post(login_url, body: {'username':'1234','password':'1234@2018'});
  print('Response status: ${login_response.statusCode}');
  print('Response body: ${login_response.body}');

  var otp_url = 'https://test.site.com/index.php/index';
  var otp_response = await client.post(otp_url,  body: {'verfication_code': TOTP("WRELBKVQMDBJDWER").now(),'user_id':'lzpZSd'});
  print('Response status: ${otp_response.statusCode}');
  print('Response body: ${otp_response.body}');

  var time_sheet_url = 'https://test.site.com/index.php/timemanagement/attendance/getemployeeattendance/format/json';
  var time_sheet_res = await client.post(time_sheet_url, body: {'userId': '199','selectedDate':'12-Nov-2019'});
  print('Response status: ${time_sheet_res.statusCode}');
  print('Response body: ${time_sheet_res.body}');
}

JSON response in the network tab

enter image description here

0 个答案:

没有答案