dqde43215 2013-09-25 17:43
浏览 374
已采纳

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

I am attempting to download a track from http://freemusicarchive.org. Generally speaking, you can download a file by appending /download to the track URL, which responds with a redirect to the asset on S3.

For example, try this link: http://freemusicarchive.org//music//Zola_Jesus//Live_at_WFMU_on_Scott_McDowells_Show_1709//Odessa/download

To see the redirect, put that link here: http://www.wheregoes.com/retracer.php

I am able to get the redirect location with code that looks like this:

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")

I have verified the redirect link works by printing it to the console and copy/pasting it into my browser, but when I call http.Get on the same url, I get a "SignatureDoesNotMatch" error from AWS.

If anyone can offer insight as to what is going wrong here, I would greatly appreciate it.

  • 写回答

1条回答 默认 最新

  • duanfu3884 2013-09-25 18:37
    关注

    Figured it out. Go parses unicode back to plain-text when processing a url. I needed to use request.URL.Opaque.

    More info here: 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料