Php gem[Ruby]通过webproxy[windows]连接
我在问一个古老的问题,当使用RubyGem时,如何通过代理 我尝试设置env变量Php gem[Ruby]通过webproxy[windows]连接,php,ruby,windows,xampp,gem,Php,Ruby,Windows,Xampp,Gem,我在问一个古老的问题,当使用RubyGem时,如何通过代理 我尝试设置env变量HTTP\u 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:
HTTP\u 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;
有什么想法吗?代理服务器,特别是身份验证代理服务器,可以在所有类型的自动更新服务中使用扳手。不幸的是,
gem
没有正确处理HTTP\u PROXY
环境变量。简而言之,它不知道如何处理来自服务器的基本身份验证响应——即使它尝试了
长话短说,您必须设置一个本地代理服务器,负责在代理服务器中导航。它不能执行任何转换(如解压缩压缩流)
myusername:password@company.com:8080
构造不是有效的URL。我知道这是windows验证代理服务器的快捷方式,但只有@
符号后面的部分是有效的URL
查看此常见问题解答:
这个问题很常见。现在修复了PHP代理
添加新源时,gem发出
规格4_8_gz
请注意,\
表示
(点)。你所需要做的就是更换它。请注意,此操作只执行一次。其他宝石将作为其正确的文件名发送出去
应该是这样的
if (empty($_GET['_p'])) {
header('Content-type: text/html');
} else {
header('Content-type: application/gzip');
$item = $_GET['_p'];
$item = '.gz' == substr($item, -3) ? $item: str_replace('_', '.', $item);
header('Content-Disposition: filename="' . $item . '"');
$path .= $item;
}
我的完整脚本将发布在github上。HTTP\U代理需要完整的HTTP URL。尝试HTTP\u代理=http://myusername:password@proxy.com:8080次要更正:根据您的常见问题解答参考,Gem进行基本身份验证,但不进行NTLM授权。谢谢@berin的回答。我以前确实读过那份文件。#apserver是该文档中的一个建议,现在似乎已经是一个死项目。还有其他选择吗?
> gem sources -ahttp://mylocalhost/ror-proxy/
ERROR: While executing gem ... (Zlib::GzipFile::Error)
not in gzip format
if (empty($_GET['_p'])) {
header('Content-type: text/html');
} else {
header('Content-type: application/gzip');
$item = $_GET['_p'];
$item = '.gz' == substr($item, -3) ? $item: str_replace('_', '.', $item);
header('Content-Disposition: filename="' . $item . '"');
$path .= $item;
}