2016-08-05 22:04
浏览 42


So I'm doing this code.

I create a time, and pass it as an URL parameter. In my handler, I do this.

path := //some url + time.Now().String()

// put into url and execute a request. 

updatedAtVar := r.URL.Query()["updated_at"][0]

What is coming out of time.Now().String() is something like

2014-11-17 23:02:03 +0000 UTC.

What is coming out of r.URL.Query()["updated_at"][0] is

2014-11-17 23:02:03 0000 UTC.

Why does this happen?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanqujing3863
    duanqujing3863 2016-08-05 22:19

    Maybe the question should be: Why does the (not shown) query string evaluate the value "2014-11-17 23:02:03 0000 UTC" when accessed?

    Since "+" in a query string will be treated as a space when parsed (this is a historic rule) ..

    HTML 5 specifies the following transformation for submitting HTML forms with the "get" method to a web server .. SPACE is encoded as '+' or '%20'

    .. my hypothesis is the result of accessing the value in URL is really the following:

    2014-11-17 23:02:03  0000 UTC
                       ^^-- space space

    A 'correct' URL would be foo?time=2014-11-17+23:02:03+%2B0000+UTC, encoding + as %2B so it is not parsed as a space. An equivalent URL would be generated if using programmatic methods to generate URLs instead of building one by hand / string concatenation.

    点赞 评论