我正在尝试从 http://freemusicarchive.org 下载轨道.一般来说,您可以通过将/download 附加到轨道 URL 来下载文件,轨道 URL 会重定向到 S3 上的 Assets 。
要查看重定向,请将该链接放在这里: http://www.wheregoes.com/retracer.php
我可以使用如下代码获取重定向位置:
req, err := http.NewRequest("GET", url, nil)
errHndlr(err)
transport := http.Transport{}
resp, err := transport.RoundTrip(req)
defer resp.Body.Close()
errHndlr(err)
redirect := resp.Header.Get("Location")
我已通过将重定向链接打印到控制台并将其复制/粘贴到我的浏览器中来验证重定向链接是否有效,但是当我调用 http.Get 相同的 url 时,我从 AWS 收到“SignatureDoesNotMatch”错误。
如果有人能提供有关这里出了什么问题的见解,我将不胜感激。
最佳答案
想通了。 Go 在处理 url 时将 unicode 解析回纯文本。我需要使用 request.URL.Opaque。
更多信息在这里:https://stackoverflow.com/a/17322831/733860
The issue was unicode-related. There was a %2F in my command (not displayed in my original question) that Go was converting to / that should have been left as %2F (cURL was properly leaving it as %2F). Changing the %2F to %252F fixed the issue.
It also appears that when creating a new HTTP request Go will parse your unicode back to plain text, so if you have %3D in the URL you submit to the HTTP request initializer it will convert it to =. I thought an obvious solution would be to put %253D into the URL but apparently there is a bug in Go that will convert %3D to = but NOT %25 to %. I had to use the Opaque URL request (request.Url.Opaque) to get around this.
关于http - Golang - 尝试 GET 请求时来自 S3 的 SignatureDoesNotMatch 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19011717/