如下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/