【问题标题】:What is the correct URL format to send to an HTTP proxy server?发送到 HTTP 代理服务器的正确 URL 格式是什么?
【发布时间】:2013-12-01 17:41:13
【问题描述】:

当我的应用程序从服务器(通过 https)请求特定 URL 时,它会获得 301 Moved Permanently 重定向。但是 Location 标头格式错误。我看到这样的东西:

> GET https://myserver/url HTTP/1.1
< 301 Moved Permanently
< Location: https://redirectedserverhttp://myserver/url

如果我在没有主机的情况下发送请求,我会得到一个格式正确的 URL:

> GET /url HTTP/1.1
< 301 Moved Permanently
< Location: https://redirectedserver/url

我正在通过代理服务器,根据RFC 2068 第 5.1.2 节,“向代理发出请求时需要绝对URI 形式”所以看起来我'我以正确的方式进行操作,但代理响应不正确。如果我通过浏览器、curl 或 wget 尝试此操作,它可以正常工作。我看了wget代码,逻辑如下:

if( proxy && !https ) {
    use absoluteURI
} else {
    use relativeURI
}

Wget 甚至在其源代码中都有注释:

/* When using SSL over proxy, CONNECT establishes a direct
   connection to the HTTPS server.  Therefore use the same
   argument as when talking to the server directly. */

这是在某处定义的实际标准吗?如果应该使用绝对 URI 形式,为什么其他工具使用它,为什么会失败?

【问题讨论】:

  • 如果您监听网络接口的流量,您会看到标头中几乎所有的 http GET 请求都使用相对路径而不是完整路径。而不是使用完整路径,您应该考虑在 http(s) 标头中使用 Host 行(请通知@我,因为我不手动检查答案)。
  • @user2284570:我正在尝试找出在与代理通信时使用 SSL 时的协议。网络嗅探器不会告诉我任何信息,因为数据包已加密。
  • 是的,但是您可以看到 http 的结果。另外,I'm trying to figure out the protocol when using SSL while talking to the proxy,您的意思是您希望您的代理检测协议是否是 sftp 而不是 https?
  • 我在 HTTP 和 HTTPS 两种情况下都发送 GET https://&lt;host&gt;/&lt;url&gt;,但在使用 HTTPS 时,代理使用无效的重定向 URL 进行响应。如果我将其更改为 GET /&lt;url&gt; 它可以工作,但根据 RFC 我的应该也可以工作。我正在尝试确定是否应该将我的代码更改为我列出的if( proxy &amp;&amp; !https),或者我的代码是否正确而这个特定的代理是错误的。

标签: https proxy http-redirect


【解决方案1】:

您只能使用 HTTP 发送绝对 URL。无论如何,它们对 HTTPS 毫无用处因为代理看不到它们。它只看到CONNECT 标头,其他所有内容都是加密的。

响应无效 URL 的不是代理,而是服务器本身。 代理也看不到响应,也看不到响应,因为它也被加密了。

【讨论】:

  • 非常好。因此,当使用 HTTP 通过代理连接时,我需要发送绝对 URL,否则需要发送相对 URL。谢谢
【解决方案2】:

通常,您会在每个 http 请求中发送一个 http 标头。
这是一个使用歌剧蜻蜓工具为https://example.org构建的示例:

GET / HTTPS/1.1
Host: example.org
User-Agent: Opera/9.80 (X11; Linux x86_64; Edition Next) Presto/2.12.378 Version/12.50
Accept: text/html, application/xml;q=0.9, application/xhtml xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: en
Accept-Charset: iso-8859-1, utf-8, utf-16, utf-32, *;q=0.1
Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
Connection: Keep-Alive, TE
TE: deflate, gzip, chunked, identity, trailers

回复:

HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Sun, 24 Nov 2013 01:38:41 GMT
Etag: "359670651"
Expires: Sun, 01 Dec 2013 01:38:41 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (mia/41C4)
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270

<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

    }
    div {
        width: 600px;
        margin: 5em auto;
        padding: 50px;
        background-color: #fff;
        border-radius: 1em;
    }
    a:link, a:visited {
        color: #38488f;
        text-decoration: none;
    }
        @media (max-width: 700px) {
            body {
                background-color: #fff;
            }
            div {
                width: auto;
                margin: 0 auto;
                border-radius: 0;
                padding: 1em;
            }
        }
        </style>    
    </head>

    <body>
        <div>
            <h1>Example Domain</h1>
            <p>This domain is established to be used for illustrative examples in documents.   You may use this
        domain in examples without prior coordination or asking for permission.</p>
            <p><a href="http://www.iana.org/domains/example">More information...</a></p>
        </div>
    </body>
</html>

由于所有浏览器都会使用相对路径发送请求,因此代理开发人员可能会认为不值得为这部分标准操心......

【讨论】:

  • 这不能回答我的问题。我知道我可以通过发送/url 而不是http://host/url 使其在这种特殊情况下工作,但我需要知道这是否是解决问题的一个好的通用 解决方案,或者它是否会解决这个代理并破坏了许多其他代理。
  • @GraemePerrow :如果代理不支持相对路径,则意味着没有 Web 浏览器无法使用它,因为它们在 Http 标头中使用 Host: 而不是完整路径。所以,它不应该破坏其他代理......
  • @user2284570:向代理 (RFC2616) 发出请求时需要绝对URI 形式
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-31
  • 2020-04-04
  • 1970-01-01
  • 2013-07-03
  • 1970-01-01
  • 2018-10-08
  • 2020-10-28
相关资源
最近更新 更多