【发布时间】:2011-06-02 18:55:46
【问题描述】:
我在问这个古老的问题,关于在使用 ruby gem 时如何通过代理。
我尝试设置环境变量HTTP_PROXY:
HTTP_PROXY=myusername:password@proxy.com:8080
但这不起作用。
> gem install rails
ERROR: While executing gem ... (URI::InvalidURIError)
bad URI(is not URI?): http://myusername:password@proxy.com:8080
我尝试在开头添加tcp://,但它在错误消息中显示http://tcp://,所以我认为这也是错误的。
所以,我尝试使用以下代码通过 php 自动连接:
<?php
$path = 'http://rubygems.org/';
$auth = base64_encode('myusername:password');
file_put_contents('proxy.log', 'POST::', FILE_APPEND);
file_put_contents('proxy.log', print_r($_POST, true), FILE_APPEND);
file_put_contents('proxy.log', 'GET::', FILE_APPEND);
file_put_contents('proxy.log', print_r($_GET, true), FILE_APPEND);
$aContext = array(
'http' => array(
'method' => 'GET',
'content' => http_build_query($_GET),
'proxy' => 'tcp://proxy.com:8080',
'request_fulluri' => true,
'header' => "Proxy-Authorization: Basic $auth"
)
);
$cxContext = stream_context_create($aContext);
$sFile = file_get_contents($path, false, $cxContext);
header('Content-type: application/gzip');
echo $sFile;
如果它试图获取特定文件,我使用 apache 处理它。
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ http://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L]
RewriteCond $1 !^$
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php?$1 [QSA,L]
</IfModule>
# Options -Indexes
但我仍然收到此错误。
> gem sources -ahttp://mylocalhost/ror-proxy/
ERROR: While executing gem ... (Zlib::GzipFile::Error)
not in gzip format
有什么想法吗?
【问题讨论】:
-
HTTP_PROXY 需要完整的 HTTP URL。试试
HTTP_PROXY=http://myusername:password@proxy.com:8080
标签: php ruby windows xampp gem