通常,ftp url格式为ftp://user[:pass]@ip[:port]/path
但现在我收到了这个字符串:
ftp://dude:1.1.1.1@1.1.1.1/@1.1.1.1/fml
它似乎不明确,因为解析结果可能是:
password=1.1.1.1, path=@1.1.1.1/fml
password=1.1.1.1@1.1.1.1/, path=fml
我是否应该告诉客户这是非法的,还是有更友好的方式来处理它?感谢..
答案 0 :(得分:4)
用户名和密码中的特殊字符
如果远程服务器需要身份验证,则可以在输入url字符串中包含用户名和密码。用户名和密码应具有以下特殊字符百分比编码:
] [? /< 〜#`! @ $%^& *()+ =} | :" ; ' ,> {space
示例:
http://example.com/path/to/input.avi
https://example.com/path/to/input.mov
ftp://example.com/path/to/input.mp3
sftp://example.com/path/to/input.3gp
https://s3.amazonaws.com/bucket-name/input.mpeg
s3://bucket-name/input.mpeg (shorthand for the full HTTP S3 url)
Examples (with username "user" and password "pass!word"):
http://user:pass%21word@example.com/path/to/input.avi
https://user:pass%21word@example.com/path/to/input.mov
ftp://user:pass%21word@example.com/path/to/input.mp3
sftp://user:pass%21word@example.com/path/to/input.3gp
ftp://user:pass%21word@example.com/path/to/input.mp3
Some servers require the username include your domain name (username "user@example.com" and password "pass!word"):
http://user%40example.com:pass%21word@example.com/path/to/input.avi
https://user%40example.com:pass%21word@example.com/path/to/input.mov
ftp://user%40example.com:pass%21word@example.com/path/to/input.mp3
sftp://user%40example.com:pass%21word@example.com/path/to/input.3gp
ftp://user%40example.com:pass%21word@example.com/path/to/input.mp3