URL格式規範

2021-08-30 18:48:02 字數 3959 閱讀 1151

**:

先記錄下,以便以後使用。

一、格式說明

「|」 表示隔開的兩部分只能出現其中乙個,方括號括起來的表示可選,文字由雙引號」」括起來,以n*開頭表示至少n個或更多的,n的預設值為0。

二、總體格式

genericurl = scheme 「:」 schemepart

scheme = 1*[ lowalpha | digit | 「+」 | 「-」 | 「.」 ]

schemepart = *xchar | ip-schemepart

ip-schemepart = 「//」 login [ 「/」 urlpath ]

login = [ user [ 「:」 password ] 「@」 ] hostport

hostport = host [ 「:」 port ]

host = hostname | hostnumber

hostname = *[ domainlabel 「.」 ] toplabel

domainlabel = alphadigit | alphadigit *[ alphadigit | 「-」 ] alphadigit

toplabel = alpha | alpha *[ alphadigit | 「-」 ] alphadigit

alphadigit = alpha | digit

hostnumber = digits 「.」 digits 「.」 digits 「.」 digits

port = digits

user = *[ uchar | 「;」 | 「?」 | 「&」 | 「=」 ]

password = *[ uchar | 「;」 | 「?」 | 「&」 | 「=」 ]

urlpath = *xchar ; depends on protocol see section 3.1

三、常見scheme

; ftp (參見rfc959)

; gopher (參見rfc1436)

gopherurl = 「gopher://」 hostport [ / [ gtype [ selector

[ 「%09″ search [ 「%09″ gopher+_string ] ] ] ] ]

gtype = xchar

selector = *xchar

gopher+_string = *xchar

; mailto (參見 rfc822)

mailtourl = 「mailto:」 encoded822addr

encoded822addr = 1*xchar ; further defined in rfc822

; news (參見 rfc1036)

newsurl = 「news:」 grouppart

grouppart = 「*」 | group | article

group = alpha *[ alpha | digit | 「-」 | 「.」 | 「+」 | 「_」 ]

article = 1*[ uchar | 「;」 | 「/」 | 「?」 | 「:」 | 「&」 | 「=」 ] 「@」 host

; nntp (參見rfc977)

nntpurl = 「nntp://」 hostport 「/」 group [ 「/」 digits ]

; telnet

telneturl = 「telnet://」 login [ 「/」 ]

; wais (參見 rfc1625)

waisurl = waisdatabase | waisindex | waisdoc

waisdatabase = 「wais://」 hostport 「/」 database

waisindex = 「wais://」 hostport 「/」 database 「?」 search

waisdoc = 「wais://」 hostport 「/」 database 「/」 wtype 「/」 wpath

database = *uchar

wtype = *uchar

wpath = *uchar

; prospero

prosperourl = 「prospero://」 hostport 「/」 ppath *[ fieldspec ]

ppath = psegment *[ 「/」 psegment ]

psegment = *[ uchar | 「?」 | 「:」 | 「@」 | 「&」 | 「=」 ]

fieldspec = 「;」 fieldname 「=」 fieldvalue

fieldname = *[ uchar | 「?」 | 「:」 | 「@」 | 「&」 ]

fieldvalue = *[ uchar | 「?」 | 「:」 | 「@」 | 「&」 ]

四、雜類

lowalpha = 「a」 | 「b」 | 「c」 | 「d」 | 「e」 | 「f」 | 「g」 | 「h」 |

「i」 | 「j」 | 「k」 | 「l」 | 「m」 | 「n」 | 「o」 | 「p」 |

「q」 | 「r」 | 「s」 | 「t」 | 「u」 | 「v」 | 「w」 | 「x」 |

「y」 | 「z」

hialpha = 「a」 | 「b」 | 「c」 | 「d」 | 「e」 | 「f」 | 「g」 | 「h」 | 「i」 |

「j」 | 「k」 | 「l」 | 「m」 | 「n」 | 「o」 | 「p」 | 「q」 | 「r」 |

「s」 | 「t」 | 「u」 | 「v」 | 「w」 | 「x」 | 「y」 | 「z」

alpha = lowalpha | hialpha

digit = 「0″ | 「1″ | 「2″ | 「3″ | 「4″ | 「5″ | 「6″ | 「7″ |

「8″ | 「9″

safe = 「$」 | 「-」 | 「_」 | 「.」 | 「+」

extra = 「!」 | 「*」 | 「『」 | 「(」 | 「)」 | 「,」

national = 「」 | 「|」 | 「\」 | 「^」 | 「~」 | 「[」 | 「]」 | 「`」

punctuation = 「<」 | 「>」 | 「#」 | 「%」 | <」>

reserved = 「;」 | 「/」 | 「?」 | 「:」 | 「@」 | 「&」 | 「=」

hex = digit | 「a」 | 「b」 | 「c」 | 「d」 | 「e」 | 「f」 |

「a」 | 「b」 | 「c」 | 「d」 | 「e」 | 「f」

escape = 「%」 hex hex

unreserved = alpha | digit | safe | extra

uchar = unreserved | escape

xchar = unreserved | reserved | escape

digits = 1*digit

URL格式解析

一 url格式 例如 http表示要通過http協議來定位網路資源。host 表示合法的網際網路主機網域名稱或者ip位址。port 用於表示在傳輸層上交換資訊的程序埠號,http協議預設埠號為80,當然採用不同的協議預設埠號不同。abs path 指定請求資源的uri 統一資源定位符 paramet...

url語法格式

url由三部分組成 資源型別 存放資源的主機網域名稱 資源檔名。url的一般語法格式為 帶方括號的為可選項 protocol hostname port path parameters query fragment protocol 協議 指定使用的傳輸協議,下表列出 protocol 屬性的有效方...

URL位址格式

1 傳統形式的url schema host port path?query fragment schema 協議。例如http https ftp等 port 埠號,http預設埠80,可以省略 path 路徑,例如 web a b query 請求引數,例如 uname zhaoli age 2...