gpt4 book ai didi

http - 如何转义golang GET请求中的空格字符

转载 作者:IT王子 更新时间:2023-10-29 00:37:46 30 4
gpt4 key购买 nike

我想在 golang 中使用 net/http 包在 get 请求中发送一个文本字符串。但我无法找到如何做到这一点。就像我想点击以下网址:

"http://api.example.com/tutor?message=how can I do this"

请让我知道我该怎么做。

最佳答案

使用这个:

resp, err := http.Get("http://api.example.com/tutor?message=" + url.QueryEscape("how can I do this"))

其中 url net/url package .

如果有多个查询参数,可以使用

p := url.Values{"message": {"hown ca I do this"}, "other": "whatever"}
resp, err := http.Get(`http://api.example.com/tutor?` + p.Encode())

关于http - 如何转义golang GET请求中的空格字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32341589/

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