1

我正在使用 Typhoeus gem 来运行 HTTP 请求。但是当我在另一个系统中运行时,它运行良好并返回正确的主 IP。但在我的系统中,它没有给出主 IP——而是返回 nil。

我的代码就像

request = Typhoeus.post("www.google.com")

在另一个系统中的响应:

Typhoeus::Response:0xb45c1f70 @options={:httpauth_avail=>0, :total_time=>0.101638, :starttransfer_time=>0.10146, :appconnect_time=>0.0, :pretransfer_time=>0.035663, :connect_time=>0.035659, :namelookup_time=> 0.00018, :effective_url=>" http://www.google.com ", :primary_ip=>"74.125.236.48", :response_code=>405, :redirect_count=>0, :return_code=>:ok,

我的系统中的响应:

Typhoeus::Response:0xbc9704c @options={:httpauth_avail=>0, :total_time=>0.589821, :starttransfer_time=>0.419524, :appconnect_time=>nil, :pretransfer_time=>0.194883, :connect_time=>0.194829, :namelookup_time=> 0.02522, :effective_url=>" http://www.google.com ", :primary_ip=>nil, :response_code=>200, :redirect_count=>0, :return_code=>:ok,

我想知道为什么会这样。我正在等待好的答案。

更新

来自另一个系统的完整响应:

Typhoeus::Response:0xb4cebdb4 @options={:httpauth_avail=>0, :total_time=>0.077503, :starttransfer_time=>0.077249, :appconnect_time=>0.0, :pretransfer_time=>0.013626, :connect_time=>0.01362, :namelookup_time=> 0.000143, :effective_url=>" http://www.google.com ", :primary_ip=>"74.125.236.50", :response_code=>405, :redirect_count=>0, :return_code=>:ok, :response_headers= >"HTTP/1.1 405 Method Not Allowed\r\nAllow: GET, HEAD\r\nDate: Thu, 10 Apr 2014 12:42:44 GMT\r\nContent-Type: text/html; charset=UTF-8\ r\n服务器:gws\r\n内容长度:1453\r\nX-XSS-保护:1;模式=块\r\nX-Frame-Options:SAMEORIGIN\r\n备用协议:80:quic\r\ n\r\n", :response_body=>"\n\n \n \n 错误 405(方法不允许)!!1\n \n {margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max -宽度:390 像素;最小高度:180 像素;填充:30 像素 0 15 像素}> body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{ color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding- right:0}}#logo{background:url(//www.google.com/images/errors/logo_sm_2.png) no-repeat}@media only screen and (min-resolution:192dpi){#logo{background: url(//www.google.com/images/errors/logo_sm_2_hr.png) 无重复 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/ errors/logo_sm_2_hr.png) 0}}@media 仅屏幕和 (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr. png) 不重复;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:55px;width:150px}\n \n \n

405.那\xE2\x80\x99是一个错误。\n

请求方法POST不适合 URL /。我们所知道的\xE2\x80\x99s。\n", :debug_info=>#}, @request=#:post}, @options={:method=>:post, :headers=>{"User-Agent "=>"Typhoeus - https://github.com/typhoeus/typhoeus "}, :maxredirs=>50}, @on_headers=[], @response=#, @on_complete=[], @on_failure=[]>

来自我的系统的完整响应:

Typhoeus::Response:0xbf277e4 @options={:httpauth_avail=>0, :total_time=>0.542332, :starttransfer_time=>0.374829, :appconnect_time=>nil, :pretransfer_time=>0.192083, :connect_time=>0.192035, :namelookup_time=> 0.025185, :effective_url=>" http://www.google.com", :primary_ip=>nil, :response_code=>200, :redirect_count=>0, :return_code=>:ok, :response_headers=>"HTTP/1.1 200 OK\r\n日期:2014 年 4 月 10 日星期四 12:44 :38 GMT\r\n过期:-1\r\n缓存控制:私有,max-age=0\r\n内容类型:文本/html;charset=ISO-8859-1\r\nSet-Cookie: PREF=ID=075796115d23a806:FF=0:TM=1397133878:LM=1397133878:S=9K9PiB355V_pLs56; expires=星期六,2016 年 4 月 9 日 12:44:38 GMT;路径=/; domain=.google.com\r\nSet-Cookie: NID=67=lbUdPyBSFruSAjPvOJZJhr25WNN43JzP--0oYtYxHvMxYYJqeWZBj8wRZi6qMPxw7XPHHylholrcflVZ-SpIdci8GL_guJcfAnh1O8XJHKQb3Qu67MA62L-bhlCbvgST; 过期=格林威治标准时间 2014 年 10 月 10 日星期五 12:44:38;路径=/; 域=.google.com;HttpOnly\r\nP3P: CP=\"这不是 P3P 政策!请参阅http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657png) 0 -258px 重复 x;边框:无;颜色:#000;光标:指针;高度:30 像素;边距:0;轮廓:0;字体:15 像素 arial,无衬线;垂直对齐:顶部}。 lsb:active{background:#ccc}.lst:focus{outline:none}#addlang a{padding:0 3px}(function(){var src='/images/nav_logo176.png';var iesg=false;document .body.onload = function(){window.n && window.n();if (document.images){new Image().src=src;}\nif (!iesg){document.f&&document.fqfocus() ;document.gbqf&&document.gbqf.q.focus();}\n}\n})(); 搜索 http://www.google.com/imghp?hl=en&tab=wi\">图片 http://maps.google.com/maps?hl=en&tab=wl\">地图 https://play.google .com/?hl=en&tab=w8\">播放 http://www.youtube.com/?tab=w1\">YouTube http://news.google.com/nwshp?hl=en&tab=wn\" >新闻 https://mail.google.com/mail/?tab=wm\">Gmail https:

 高级搜索语言工具
广告程序商业解决方案https://plus.google.com/116899029375914044550\" rel=\"publisher\">+GoogleAbout Google© 2013 - 隐私和条款

if(google.y)google.y.first=[];(function(){function b(a){window.setTimeout(function(){var c=document.createElement(\"script\");c. src=a;document.getElementById(\"xjsd\").appendChild(c)},0)}google.dljp=function(a){google.xjsu=a;b(a)};google.dlj=b ;})();\nif(!google.xjs){window._=window._||{};window._._DumpException=function(e){throw e};if(google.timers&&google.timers. load.t){google.timers.load.t.xjsls=new Date().getTime();}google.dljp('/xjs/_/js/k\\x3dxjs.hp.en_US.75bv2nh_qxI.O/ m\\x3dsb_he,pcc/rt\\x3dj/d\\x3d1/sv\\x3d1/rs\\x3dAItRSTOX5WMsAVpkgEafYeVKZ7ZCJdNXcg');google.xjs=1;}google.pmc={\"sb_he\":{\" agen\":true,\"cgen\":true,\"client\":\"heirloom-hp\",\"dh\":true,\"ds\":\"\",\"eqch \":真,\"fl\":真,\"host\":\"google.com\",\"jam\":0,\"jsonp\":true,\"msgs\":{\"dym\":\"你的意思是:\", \"lcky\":\"I\\u0026#39;m 手气\",\"lml\":\"了解更多\",\"oskt\":\"输入工具\",\"psrc \":\"此搜索已从您的 \\u003Ca href=\\\"/history\\\"\\u003EWeb History\\u003C/a\\u003E\",\"psrl\":\"删除\",\"sbit\":\"按图片搜索\",\"srch\":\"谷歌搜索\"},\"ovr\":{},\"pq\":\"\" ,\"qcpw\":false,\"scd\":10,\"sce\":5,\"stok\":\"nXO_Z2rNte7VdOqPtwZ_V-hNE4c\"},\"pcc\":{}}; google.y.first.push(function(){if(google.med){google.med('init');google.initHistory();google.med('history');}});if(google.j&&google.j.en&&google.j.xi){window.setTimeout(google.j.xi,0);}(function() {if(google.timers&&google.timers.load.t){var b,c,d,e,g=function(a,f){a.removeEventListener?(a.removeEventListener(\"load\",f,! 1),a.removeEventListener(\"error\",f,!1)):(a.detachEvent(\"onload\",f),a.detachEvent(\"onerror\",f))},h =function(a){e=(new Date).getTime();++c;a=a||window.event;a=a.target||a.srcElement;g(a,h)},k =document.getElementsByTagName(\"img\");b=k.length;for(var l=c=0,m;l", :debug_info=>#}, @request=#:post}, @options= {:method=>:post, :headers=>{"User-Agent"=>"Typhoeus -0);}(function(){if(google.timers&&google.timers.load.t){var b,c,d,e,g=function(a,f){a.removeEventListener?(a.removeEventListener(\ "load\",f,!1),a.removeEventListener(\"error\",f,!1)):(a.detachEvent(\"onload\",f),a.detachEvent(\"onerror\ ",f))},h=function(a){e=(new Date).getTime();++c;a=a||window.event;a=a.target||a.srcElement;g (a,h)},k=document.getElementsByTagName(\"img\");b=k.length;for(var l=c=0,m;l", :debug_info=>#}, @request= #:post}, @options={:method=>:post, :headers=>{"User-Agent"=>"Typhoeus -0);}(function(){if(google.timers&&google.timers.load.t){var b,c,d,e,g=function(a,f){a.removeEventListener?(a.removeEventListener(\ "load\",f,!1),a.removeEventListener(\"error\",f,!1)):(a.detachEvent(\"onload\",f),a.detachEvent(\"onerror\ ",f))},h=function(a){e=(new Date).getTime();++c;a=a||window.event;a=a.target||a.srcElement;g (a,h)},k=document.getElementsByTagName(\"img\");b=k.length;for(var l=c=0,m;l", :debug_info=>#}, @request= #:post}, @options={:method=>:post, :headers=>{"User-Agent"=>"Typhoeus -detachEvent(\"onerror\",f))},h=function(a){e=(new Date).getTime();++c;a=a||window.event;a=a.target| |a.srcElement;g(a,h)},k=document.getElementsByTagName(\"img\");b=k.length;for(var l=c=0,m;l", :debug_info=> #}, @request=#:post}, @options={:method=>:post, :headers=>{"User-Agent"=>"Typhoeus -detachEvent(\"onerror\",f))},h=function(a){e=(new Date).getTime();++c;a=a||window.event;a=a.target| |a.srcElement;g(a,h)},k=document.getElementsByTagName(\"img\");b=k.length;for(var l=c=0,m;l", :debug_info=> #}, @request=#:post}, @options={:method=>:post, :headers=>{"User-Agent"=>"Typhoeus -https://github.com/typhoeus/typhoeus "}, :maxredirs=>50}, @on_headers=[], @response=#, @on_complete=[], @on_success=[]>

4

0 回答 0