,
第一行要求就像例如
GET /img/my house.jpg HTTP/1.1
我的问题是,如果文件名有空格,协议是否要求以某种方式对其进行编码? (如果协议不清楚,实际情况是什么?)
答案 0 :(得分:4)
答案 1 :(得分:4)
你必须将它编码为%20,这就是原因。首先,RFC 2616第5.1.2节......
Request-Line =方法SP Request-URI SP HTTP-Version CRLF
和...
Request-URI =“*”| absoluteURI | abs_path |权威
现在让我们跳到RFC 1808,你会注意到URL和路径规范中缺少空格......
URL = ( absoluteURL | relativeURL ) [ "#" fragment ]
absoluteURL = generic-RL | ( scheme ":" *( uchar | reserved ) )
generic-RL = scheme ":" relativeURL
relativeURL = net_path | abs_path | rel_path
net_path = "//" net_loc [ abs_path ]
abs_path = "/" rel_path
rel_path = [ path ] [ ";" params ] [ "?" query ]
path = fsegment *( "/" segment )
fsegment = 1*pchar
segment = *pchar
params = param *( ";" param )
param = *( pchar | "/" )
scheme = 1*( alpha | digit | "+" | "-" | "." )
net_loc = *( pchar | ";" | "?" )
query = *( uchar | reserved )
fragment = *( uchar | reserved )
pchar = uchar | ":" | "@" | "&" | "="
uchar = unreserved | escape
unreserved = alpha | digit | safe | extra
escape = "%" hex hex
hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |
"a" | "b" | "c" | "d" | "e" | "f"
alpha = lowalpha | hialpha
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"
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
"8" | "9"
safe = "$" | "-" | "_" | "." | "+"
extra = "!" | "*" | "'" | "(" | ")" | ","
national = "{" | "}" | "|" | "\" | "^" | "~" | "[" | "]" | "`"
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "="
punctuation = "<" | ">" | "#" | "%" | <">
答案 2 :(得分:3)
是
规范定义了请求行,如下所示:
Request-Line = Method SP Request-URI SP HTTP-Version CRLF
请注意,空格是请求行中的分隔符。
答案 3 :(得分:2)
是。 %20
。有关详细信息,请参阅RFC 1738。
您应该记住,HTTP URI的路径组件不是“文件路径”。它只是资源的分层路径,它不需要与服务器上的任何文件相对应。
答案 4 :(得分:2)
空间需要编码为%20,编码规则记录在RFC3986中。你通常最好让图书馆负责网址编码。