我试图弄清楚代理连接如何通过 TCP 工作。我首先下载了 stacksoft 库并在远程服务器上安装了 Squid 代理。
现在我正在尝试通过 c# TcpClient 连接到它。
连接由以下请求打开:
CONNECT proxyjudge.iathao.com:80 HTTP/1.1
HOST proxyjudge.iathao.com
失败并显示错误代码 400(我尝试了几种变体,它总是失败):
HTTP/1.0 400 Bad Request
Server: squid/3.1.10
Mime-Version: 1.0
Date: Mon, 27 Aug 2012 13:25:54 GMT
Content-Type: text/html
Content-Length: 3295
X-Squid-Error: ERR_INVALID_REQ 0
Vary: Accept-Language
Content-Language: en
X-Cache: MISS from ****
X-Cache-Lookup: NONE ****:***
Connection: close
....
<h1>ERROR</h1>
<h2>The requested URL could not be retrieved</h2>
....
<div id="content">
<p><b>Invalid Request</b> error was encountered while trying to process the request:</p>
<blockquote id="data">
<pre>CONNECT proxyjudge.iathao.com:80 HTTP/1.1
HOST proxyjudge.iathao.com
</pre>
</blockquote>
<p>Some possible problems are:</p>
<ul>
<li><p>Missing or unknown request method.</p></li>
<li><p>Missing URL.</p></li>
<li><p>Missing HTTP Identifier (HTTP/1.0).</p></li>
<li><p>Request is too large.</p></li>
<li><p>Content-Length missing for POST or PUT requests.</p></li>
<li><p>Illegal character in hostname; underscores are not allowed.</p></li>
<li><p>HTTP/1.1 <q>Expect:</q> feature is being asked from an HTTP/1.0 software.</p></li>
</ul>
所以我用wireshark跟踪了firefox发送到同一台服务器的请求,它看起来像一个普通的get请求,看不到连接命令:
GET http://proxyjudge.iathao.com/ HTTP/1.1
Host: proxyjudge.iathao.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Proxy-Connection: keep-alive
======================================================
HTTP/1.0 200 OK
Date: Mon, 27 Aug 2012 13:34:39 GMT
Server: Apache
X-Powered-By: PHP/5.3.15
Content-Type: text/html
X-Cache: MISS from ****
X-Cache-Lookup: MISS from ****:****
Connection: close
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>AZ Environment variables 1.04</title>
</head>
<body>
<pre>
HTTP_USER_AGENT = Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1
HTTP_HOST = proxyjudge.iathao.com
REQUEST_URI = /
HTTP_CONNECTION = keep-alive
REMOTE_PORT = 46153
HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5
HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
REMOTE_ADDR = ****
HTTP_CACHE_CONTROL = max-age=259200
HTTP_ACCEPT_ENCODING = gzip, deflate
REQUEST_METHOD = GET
REQUEST_TIME = 1346074479
</pre>
</body>
</html>
我在任何地方都读到 CONNECT 是必要的,但在这里它会导致错误。如果不需要连接,我如何在受密码保护的代理上授权连接?
谁能推荐一篇关于这个主题的好文章?