gpt4 book ai didi

url - Golang 中包含大括号的错误请求 400

转载 作者:IT王子 更新时间:2023-10-29 02:26:13 28 4
gpt4 key购买 nike

来自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}')

很有魅力。

在围棋中,

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

导致错误请求 (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}"))

您可能需要将 + 改回空格,因为它们正在被转义。

关于url - Golang 中包含大括号的错误请求 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50066825/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com