小编Rox*_*Ben的帖子

GoLang - 遵循带有正文数据的 POST 请求的重定向

我想对 POST 请求使用相同的正文进行重定向。

来自 GO 来源 (client.go)

func redirectBehavior(reqMethod string, resp *Response, ireq *Request) (redirectMethod string, shouldRedirect, includeBody bool) {
    switch resp.StatusCode {
    case 301, 302, 303:
        redirectMethod = reqMethod
        shouldRedirect = true
        includeBody = false

        // RFC 2616 allowed automatic redirection only with GET and
        // HEAD requests. RFC 7231 lifts this restriction, but we still
        // restrict other methods to GET to maintain compatibility.
        // See Issue 18570.
Run Code Online (Sandbox Code Playgroud)

但有时服务器会为 POST 请求返回 302 Redirect,这意味着我需要将相同的正文发送到另一个位置。

在这种情况下我该怎么办?

func FollowRedirectForPost() {
    client …
Run Code Online (Sandbox Code Playgroud)

networking httpclient httprequest go

2
推荐指数
1
解决办法
4429
查看次数

标签 统计

go ×1

httpclient ×1

httprequest ×1

networking ×1