我快疯了,我有一个非常简单的 WEBrickProxy(WEBrick 1.3.1,带有 Ruby 1.9.3),我想用 curl 试试。这是代理:
require 'webrick'
require 'webrick/httpproxy'
server = WEBrick::HTTPProxyServer.new(:BindAddress => "localhost", :Port => 8888)
trap('INT') { server.shutdown }
server.start
这是 cURL 命令
curl --proxy localhost:8888 http://www.google.de -v
但是 curl 命令总是返回一个错误的请求:
* About to connect() to proxy localhost port 8888 (#0)
* Trying ::1...
* connected
* Connected to localhost (::1) port 8888 (#0)
> GET http://www.google.de HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: www.google.de
> Accept: */*
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 400 Bad Request
< Content-Type: text/html; charset=ISO-8859-1
< Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-10-12)
< Date: Mon, 18 Mar 2013 13:44:27 GMT
< Content-Length: 295
< Connection: close
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD><TITLE>Bad Request</TITLE></HEAD>
<BODY>
<H1>Bad Request</H1>
bad URI `http://www.google.de'.
<HR>
<ADDRESS>
WEBrick/1.3.1 (Ruby/1.9.3/2012-10-12) at
23tuxmb.local:8888
</ADDRESS>
</BODY>
</HTML>
* Closing connection #0
curl --version
在我的 Mac OS X 10.8 上返回
curl 7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IPv6 Largefile NTLM NTLM_WB SSL libz
我找不到错误在哪里,几周前我尝试了那段代码,我记得它有效。
奇怪的是,当我将我的 Mac 配置为全局使用该代理(在内部System Settings -> Network -> Advanced -> Proxies -> Web Proxy
)时,一切正常。Chrome 或任何其他应用程序的请求通过代理进行路由(我在代理的终端日志中看到了这一点)。
那么,任何人都可以重现这个问题吗?它是一个卷曲错误吗?还是与 Webrick 相关的问题?
编辑
更多信息:当 curl 尝试连接时,ruby 脚本本身的输出是
[2013-03-18 17:16:32] ERROR bad URI `http://www.amazon.de'.
localhost - - [18/Mar/2013:17:16:32 CET] "GET http://www.amazon.de HTTP/1.1" 400 286
- -> http://www.amazon.de
谢谢!