URL通用格式

URL general format

本文关键字:格式 URL      更新时间:2023-10-16

我写了一个c++程序,允许在YouTube上发布url。它的工作原理是将URL作为输入,要么从您输入到程序中,要么从直接输入,然后它将替换每个'/','。'*'在字符串中。然后将修改后的字符串放在剪贴板上(这仅适用于windows用户)。

当然,在我甚至可以调用程序可用之前,它必须返回:我需要知道什么时候。', '/'在url中使用。我看过这篇文章:http://en.wikipedia.org/wiki/Uniform_Resource_Locator,并且知道。'在处理"主网站"时使用(在此URL的情况下,"en.wikipedia.org"),然后使用'/',但我去过其他网站,http://msdn.microsoft.com/en-us/library/windows/desktop/ms649048%28v=vs.85%29.aspx,这根本不是这种情况(它甚至用"%28","%29"分别替换了'(',')' !

我似乎也请求了一个。aspx文件,不管那是什么。还有一个'。'在URL的括号内。我甚至尝试查看关于url的正则表达式(我还不完全理解那些…)。有人能告诉我(或链接给我)关于'。', '/'在url中?

你能解释一下你为什么要做这种令人费解的事情吗?你想达到什么目标?一旦你回答了这个问题,你可能并不需要知道你想的那么多。

同时这里有一些信息。URL实际上是由许多部分组成的

http:     - the "scheme" or protocol used to access the resource. "HTTP", "HTTPS",
            "FTP", etc are all examples of a scheme. There are many others
//        - separates the protocol from the host (server) address
myserver.org - the host. The host name is looked up against a DNS (Dynamic Name Server)
            service and resolved to an IP address - the "phone number" of the machine
            which can serve up the resource (like "98.139.183.24" for www.yahoo.com)
www.myserver.org - the host with a prefix. Sometimes the same domain (`myserver.org`)
            connects multiple servers (or ports) and you can be sent straight to the
            right server with the prefix (mail., www., ftp., ... up to the
            administrators of the domain). Conventionally, a server that serves content
            intended for viewing with a browser has a `www.` prefix, but there's no rule
            that says this must be the case. 
:8080/    - sometimes, you see a colon followed by up to five digits after the domain.
            this indicates the PORT on the server where you are accessing data
            some servers allow certain specific services on just a particular port
            they might have a "public access" website on port 80, and another one on 8080
            the https:// protocol defaults to port 443, there are ports for telnet, ftp, 
            etc. Add these things only if you REALLY know what you are doing.
/the/pa.th/ this is the path relative to DOCUMENTROOT on the server where the
            resource is located. `.` characters are legal here, just as they are in
            directory structures. 
file.html
file.php
file.asp
etc       - usually the resource being fetched is a file. The file may have
            any of a great number of extensions; some of these indicate to the server that
            instead of sending the file straight to the requester,
            it has to execute a program or other instructions in this file,
            and send the result of that
            Examples of extensions that indicate "active" pages include
            (this is not nearly exhaustive - just "for instance"):
            .php = contains a php program
            .py  = contains a python program
            .js  = contains a javascript program
                   (usually called from inside an .htm or .html)
            .asp = "active server page" associated with a
                   Microsoft Internet Information Server

? = value&换掉= % 23 othervalue % 23传递给服务器的参数可以显示在URL中。这可以用来传递参数、表单中的条目等。任何字符都可以在这里传递-包括'。', '&', '/',…但是你不能只把这些字符写在你的字符串中…

现在是有趣的部分。

url不能包含某些字符(实际上相当多)。为了解决这个问题,存在一种称为"转义"字符的机制。通常,这意味着用十六进制等效字符替换一个字符,前缀为%符号。因此,您经常会看到一个空格字符表示为%20。你可以在这里找到一个手柄列表

有许多函数可用于自动将URL中的"非法"字符转换为"合法"值。

要了解什么是允许的,什么是不允许的,你真的需要回到最初的规范。参见

http://www.ietf.org/rfc/rfc1738.txt

http://www.ietf.org/rfc/rfc2396.txt

http://www.ietf.org/rfc/rfc3986.txt

我按时间顺序列出它们——最后一个是最近的。

但我重复我的问题——你在这里真正想做什么,为什么?