gpt4 book ai didi

http - Go中的ResolveReference时如何避免删除URL斜杠的结尾

转载 作者:IT王子 更新时间:2023-10-29 02:17:23 24 4
gpt4 key购买 nike

在下面example , URL 的结尾 / 被删除了,有没有办法保留 /

package main

import (
"fmt"
"net/url"
"path"
)

func main() {
u, _ := url.Parse("http://localhost:5100")
relative, _ := url.Parse(path.Join("hello/"))
fmt.Println(u.ResolveReference(relative))
}

输出:

http://localhost:5100/hello

最佳答案

我想出了答案,那就是不使用path.Join:

package main

import (
"fmt"
"net/url"
)

func main() {
u, _ := url.Parse("http://localhost:5100")
relative, _ := url.Parse("hello/")
fmt.Println(u.ResolveReference(relative))
}

输出:

http://localhost:5100/hello/

关于http - Go中的ResolveReference时如何避免删除URL斜杠的结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23051339/

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