Mic*_*ner 0 url curly-braces go
来自Python
import requests
requests.get('https://git.eclipse.org/r/changes/?q=since:{2018-01-01 00:00:00.000}+AND+until:{2018-01-01 22:59:59.999}')
Run Code Online (Sandbox Code Playgroud)
奇迹般有效.
在Go,
client := &http.Client{Timeout: time.Second * 10}
response, err := client.Get("https://git.eclipse.org/r/changes/?q=since:{2018-01-01 00:00:00.000}+AND+until:{2018-01-01 22:59:59.999}")
Run Code Online (Sandbox Code Playgroud)
导致错误的请求(400).
我假设,问题是URL中大括号的编码.我该如何解决?
您需要转义查询字符串:
client.Get("https://git.eclipse.org/r/changes/?q=" + url.QueryEscape("since:{2018-01-01 00:00:00.000}+AND+until:{2018-01-01 22:59:59.999}"))
Run Code Online (Sandbox Code Playgroud)
+因为它们被转义,您可能需要将背面更改为空格.