http状态码 301-302 VS 307-308

问题现象:
一个POST请求, Spring java应用却返回了GET Not Supported

原因:
http POST请求到达nginx后, nginx返回了301 https url, 然后client重发了这个https url请求,但是变成了GET请求。
https升级后,通常我们希望client发送https请求,所以配置了http全部重定向到https.

解决方法:
重定向时应该使用308, 而不是301

server {
    listen 80 default_server;
    server_name _;
    return 308 https://$host$request_uri;
}

https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/308
https://github.com/square/retrofit/issues/1690
https://stackoverflow.com/questions/13628831/apache-301-redirect-and-preserving-post-data
https://softwareengineering.stackexchange.com/questions/99894/why-doesnt-http-have-post-redirect#99966

posted @ 2024-03-26 15:49  funny_coding  阅读(100)  评论(0)    收藏  举报
build beautiful things, share happiness