我疯了,我有一个非常简单的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
THX!
答案 0 :(得分:2)
如果您向所请求的网址添加尾部斜杠,那么它是否有效?就是这样的命令行:
curl --proxy localhost:8888 http://www.google.de/ -v
(这是bug #1206中报告的卷曲错误,并在git和下一个版本中修复...)