http - 相对路径,但对于端口?

标签 http url port relative-path

我们都熟悉相对路径:从 http://www.domain.com/hey 链接到 ./images/hello.jpg 的相对路径http://www.domain.com/hey/images/hello.jpg

问题当您位于http://www 时,如何声明到http://www.domain.com:1234 的相对路径.domain.com/hey?

最佳答案

您不能更改相对 URL 中 authority 的任何部分(即 host:port 部分)。 请参阅 section 5.2.2 中描述的算法的 RFC 3986查看如何解释相对 URL。需要注意的重要一点是,权限只是从基本 URL 或正在解析的 URL 中复制,并且权限的结构永远不会被解释。这意味着您不能更改它的任何部分,包括端口部分。

这是从 RFC 复制的伪代码算法:

  -- The URI reference is parsed into the five URI components
  --
  (R.scheme, R.authority, R.path, R.query, R.fragment) = parse(R);

  -- A non-strict parser may ignore a scheme in the reference
  -- if it is identical to the base URI's scheme.
  --
  if ((not strict) and (R.scheme == Base.scheme)) then
     undefine(R.scheme);
  endif;

  if defined(R.scheme) then
     T.scheme    = R.scheme;
     T.authority = R.authority;
     T.path      = remove_dot_segments(R.path);
     T.query     = R.query;
  else
     if defined(R.authority) then
        T.authority = R.authority;
        T.path      = remove_dot_segments(R.path);
        T.query     = R.query;
     else
        if (R.path == "") then
           T.path = Base.path;
           if defined(R.query) then
              T.query = R.query;
           else
              T.query = Base.query;
           endif;
        else
           if (R.path starts-with "/") then
              T.path = remove_dot_segments(R.path);
           else
              T.path = merge(Base.path, R.path);
              T.path = remove_dot_segments(T.path);
           endif;
           T.query = R.query;
        endif;
        T.authority = Base.authority;
     endif;
     T.scheme = Base.scheme;
  endif;

  T.fragment = R.fragment;

关于http - 相对路径,但对于端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8317059/

相关文章:

http - Golang *bytes.Buffer nil 导致 fatal error

c# - 使用 POST 而不是通常的 WSDL 路由来使用 Web 服务

javascript - Node.js 未处理 'error' 事件

javascript - 如何修改此 javascript 以忽略查询字符串中的任何数据?

javascript在不重定向的情况下更改get参数

windows - PhpStorm Xdebug : Port 9000 is busy, 还设置在端口 63342

c++ - 在 Android 上移植 native C++ 非静态二进制文件

c# - .NET:检查 URL 的响应状态代码?

java - 如何创建与他人共享的 URL

java - docker 运行 nginx 加 jar