duanlvxing7707 2016-08-05 22:04
浏览 115
已采纳

为什么Go作为URL参数传递时会修改UTC时间?

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]
fmt.Println(updatedAtVar)

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 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.

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog