GO語言"net/url"包中"URL.ResolveReference"類型的用法及代碼示例。
用法:
func(u *URL) ResolveReference(ref *URL) *URL
ResolveReference 根據 RFC 3986 第 5.2 節,從絕對基礎 URI u 解析對絕對 URI 的 URI 引用。 URI 引用可以是相對的或絕對的。 ResolveReference 總是返回一個新的 URL 實例,即使返回的 URL 與基本或引用相同。如果 ref 是絕對 URL,則 ResolveReference 忽略 base 並返回 ref 的副本。
例子:
package main
import (
"fmt"
"log"
"net/url"
)
func main() {
u, err := url.Parse("../../..//search?q=dotnet")
if err != nil {
log.Fatal(err)
}
base, err := url.Parse("http://example.com/directory/")
if err != nil {
log.Fatal(err)
}
fmt.Println(base.ResolveReference(u))
}
輸出:
http://example.com/search?q=dotnet
相關用法
- GO URL.Redacted用法及代碼示例
- GO URL.RequestURI用法及代碼示例
- GO URL.Hostname用法及代碼示例
- GO URL.EscapedPath用法及代碼示例
- GO URL.Port用法及代碼示例
- GO URL.Query用法及代碼示例
- GO URL.Parse用法及代碼示例
- GO URL.String用法及代碼示例
- GO URL.UnmarshalBinary用法及代碼示例
- GO URL.EscapedFragment用法及代碼示例
- GO URL.MarshalBinary用法及代碼示例
- GO URL.IsAbs用法及代碼示例
- GO URL用法及代碼示例
- GO UDPConn.WriteTo用法及代碼示例
- GO Unmarshal用法及代碼示例
- GO UnaryOp用法及代碼示例
- GO Unsetenv用法及代碼示例
- GO Unquote用法及代碼示例
- GO Unwrap用法及代碼示例
- GO UnquoteChar用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 URL.ResolveReference。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。