Flutter:308 永久重定向响应。仅在 Flutter 代码中发现问题。邮递员收到的预期回复
Flutter : 308 Permanent Redirect response. Issue found only on Flutter code. Expected response received on postman
下面是我通过 Flutter 请求 Post 网络服务时得到的响应。当我使用邮递员尝试相同的 Web 服务时,我得到了预期的响应。我错过了什么?
<html>
<head><title>308 Permanent Redirect</title></head>
<body>
<center><h1>308 Permanent Redirect</h1></center>
<hr><center>nginx</center>
</body>
</html>
下面是我的代码:
var params = {
"hostName": 'something',
"username": 'something',
"password": 'something'
}
var postBody = json.encode(params);
var uri = Uri.encodeFull('http://{{api_url}}/account/authenticate');
var response = await http.post(uri, body: postboy, headers: {HttpHeaders.contentTypeHeader: " application/json"});
print response.body;
这条评论对我有帮助:
下面是我修改后的代码:
var params = {
"hostName": 'something',
"username": 'something',
"password": 'something'
}
var postBody = json.encode(params);
var uri = Uri.encodeFull('http://{{api_url}}/account/authenticate');
var response = await http.post(uri, body: postBody, headers: {HttpHeaders.contentTypeHeader: " application/json"});
print(response.body);
//Here you get the 308 error.
final getResponse =
await http.post(response.headers["location"], body: postBody, headers: {
HttpHeaders.contentTypeHeader: "application/json",
});
print(getResponse.body); //this is the expected response
下面是我通过 Flutter 请求 Post 网络服务时得到的响应。当我使用邮递员尝试相同的 Web 服务时,我得到了预期的响应。我错过了什么?
<html>
<head><title>308 Permanent Redirect</title></head>
<body>
<center><h1>308 Permanent Redirect</h1></center>
<hr><center>nginx</center>
</body>
</html>
下面是我的代码:
var params = {
"hostName": 'something',
"username": 'something',
"password": 'something'
}
var postBody = json.encode(params);
var uri = Uri.encodeFull('http://{{api_url}}/account/authenticate');
var response = await http.post(uri, body: postboy, headers: {HttpHeaders.contentTypeHeader: " application/json"});
print response.body;
这条评论对我有帮助:
下面是我修改后的代码:
var params = {
"hostName": 'something',
"username": 'something',
"password": 'something'
}
var postBody = json.encode(params);
var uri = Uri.encodeFull('http://{{api_url}}/account/authenticate');
var response = await http.post(uri, body: postBody, headers: {HttpHeaders.contentTypeHeader: " application/json"});
print(response.body);
//Here you get the 308 error.
final getResponse =
await http.post(response.headers["location"], body: postBody, headers: {
HttpHeaders.contentTypeHeader: "application/json",
});
print(getResponse.body); //this is the expected response