I'm a newbie when it comes to Go and Gin, so please excuse my ignorance.
I've setup a server using Gin which supports a POST request. I would like the user to POST their request which includes a required JSON payload redirecting that request to another URL. As part of the redirect I need to pass the original JSON payload. For example, if the user issues this CURL request:
curl -H "Content-Type: application/json" -d '{ "name": "NewTest Network", "organizationId": 534238, "type": "wireless"}' -X POST "http://localhost:8080/network"
My Gin code does this:
r.POST("/network", func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently, networks_url)
})
where: networks_url is the redirected URL. I need a way to pass the original JSON payload to the redirected URL.
Any help you could provide would be greatly appreciated.
This doesn't have anything to do with Go or gin.
This is the expected behavior of a user agent, which should change the method from POST to GET with either a 301 or 302 redirect.
To instruct the user agent to repeat the request with the same method, use 307 (http.StatusTemporaryRedirect
) or 308 (http.StatusPermanentRedirect
).
You must use 301 or 302 as a redirect status code.
c.Redirect(301, "http://www.google.com/")
Please refer the documentation here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With