http - Golang - 尝试 GET 请求时来自 S3 的 SignatureDoesNotMatch 错误

标签 http amazon-web-services go urlencode

我正在尝试从 http://freemusicarchive.org 下载轨道.一般来说,您可以通过将/download 附加到轨道 URL 来下载文件,轨道 URL 会重定向到 S3 上的 Assets 。

例如,试试这个链接: http://freemusicarchive.org//music//Zola_Jesus//Live_at_WFMU_on_Scott_McDowells_Show_1709//Odessa/download

要查看重定向,请将该链接放在这里: 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/

相关文章:

windows - 在 Go 中连接到 Oracle DB

amazon-web-services - 使用 "alexa-app"依赖项将 Alexa 技能部署到 AWS Lambda

http - 如何非破坏性地检查 HTTP 客户端是否已关闭连接?

c - 如何使用libcurl获取网页标题

http - 将单个 HTTP header 的多个值添加到请求或响应的标准

java - 删除桶是否也会删除其对象

amazon-web-services - 了解谁创建了 CloudTrail 以及如何创建?

go - 如何在 tar 中获取 tar 中文件的所需路径

javascript - Angular 2 - Http Get 请求 - 传递 json 对象

python - 从基于 Django 类的 View 的 form_valid 方法调用特殊(非 HTTP)URL