0

我编写了一个允许将 URL 发布到 YouTube 上的 C++ 程序。它的工作原理是将 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 中使用“.”、“/”的规则吗?

4

1 回答 1

2

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

与此同时,这里有一些信息。一个 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

?something=value&somethingElse=%23othervalue%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

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

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

于 2013-04-14T04:09:58.670 回答