flutter中http.post返回307错误代码

pra*_*ale 2 flutter

我正在使用 http 客户端进行 flutter 网络调用。

  1. 我的要求是让邮递员得到正确的回应,
  2. 但是在尝试使用 http.post 时,它返回错误代码 307-临时重定向,

方法体:

static Future<http.Response> httpPost(
  Map postParam, String serviceURL) async {
Map tempParam = {"id": "username", "pwd": "password"};
var param = json.encode(tempParam);
serviceURL = "http:xxxx/Login/Login";

// temp check
Map<String, String> headers = {
  'Content-Type': 'application/json',
  'cache-control': 'no-cache',
};
await http.post(serviceURL, headers: headers, body: param).then((response) {
  return response;
});
}
Run Code Online (Sandbox Code Playgroud)

此外,相同的代码会返回对其他请求和 URL 的正确响应。首先,我尝试使用 chopper 客户端,但遇到了同样的问题。

我无法从服务器端检测到该问题。

任何帮助/提示都会有帮助

小智 12

/尝试在 的末尾添加斜杠serviceUrl。因此,serviceUrlserviceURL = "http:xxxx/Login/Login/"代替了serviceURL = "http:xxxx/Login/Login"。

这对我有用。