2012-11-06 29 views
0

當我嘗試發送HTTP請求時,出現application error Errno::ECONNREFUSED錯誤。我正在使用Sinatra,並將其設置在本地工作站上。以下是錯誤:應用程序錯誤Errno :: ECONNREFUSED在Ruby中

Errno::ECONNREFUSED - Connection refused - Connection refused: 
    org/jruby/ext/socket/RubyTCPSocket.java:124:in `initialize' 
    org/jruby/RubyIO.java:876:in `new' 
    org/jruby/ext/socket/RubyTCPSocket.java:154:in `open' 
    /Users/Banderson/.rvm/rubies/jruby-1.6.8/lib/ruby/1.8/net/http.rb:560:in `connect' 
    org/jruby/ext/Timeout.java:79:in `timeout' 
    /Users/Banderson/.rvm/rubies/jruby-1.6.8/lib/ruby/1.8/net/http.rb:560:in `connect' 
    /Users/Banderson/.rvm/rubies/jruby-1.6.8/lib/ruby/1.8/net/http.rb:553:in `do_start' 
    /Users/Banderson/.rvm/rubies/jruby-1.6.8/lib/ruby/1.8/net/http.rb:542:in `start' 
    /Users/Banderson/.rvm/rubies/jruby-1.6.8/lib/ruby/1.8/net/http.rb:1035:in `request' 
    ./ServiceRequest.rb:39:in `sendGetRequest' 
    ./fileParser.rb:148:in `parseUrls' 
    org/jruby/RubyHash.java:1181:in `each' 
    ./fileParser.rb:138:in `parseUrls' 
    org/jruby/RubyHash.java:1181:in `each' 
    ./fileParser.rb:73:in `parseUrls' 
    ./testmdxservices.rb:108:in `sendServiceRequest' 
    ./testmdxservices.rb:80:in `getFile' 
    TestServices.rb:71:in `TestServices' 
    org/jruby/RubyProc.java:270:in `call' 
    org/jruby/RubyMethod.java:117:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:1264:in `compile!' 
    org/jruby/RubyProc.java:270:in `call' 
    org/jruby/RubyProc.java:220:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `route!' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:851:in `route_eval' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `route!' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:872:in `process_route' 
    org/jruby/RubyKernel.java:1212:in `catch' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in `process_route' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:834:in `route!' 
    org/jruby/RubyArray.java:1620:in `each' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:833:in `route!' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:936:in `dispatch!' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in `call!' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `invoke' 
    org/jruby/RubyKernel.java:1212:in `catch' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `invoke' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in `call!' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:755:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/logger.rb:15:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:136:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:129:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/head.rb:9:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/showexceptions.rb:21:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:99:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:1471:in `synchronize' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in `call' 
    /Users/Banderson/.rvm/gems/jruby-1.6.8/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service' 
    /Users/Banderson/.rvm/rubies/jruby-1.6.8/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' 
    /Users/Banderson/.rvm/rubies/jruby-1.6.8/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' 
    /Users/Banderson/.rvm/rubies/jruby-1.6.8/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' 
    org/jruby/RubyProc.java:270:in `call' 
    org/jruby/RubyProc.java:224:in `call' 

這裏是我的sendGetRequest

def sendGetRequest(url, mMethod, key, rHash, headers, publicToken) 



     mKey = String.new(key) 
     nMethod =String.new(mMethod) 

     nKey = mKey.concat(nMethod) 

     uri = URI.parse(URI.encode(url)) 
     http = Net::HTTP.new(uri.host, uri.port) 

     request = Net::HTTP::Get.new(uri.request_uri) 
      headers.each do |hKey, hVal| 
       request[hKey] = hVal 
      end 

     request["Authorization"] = publicToken 

     if uri.scheme == "https" 
      http.use_ssl = true 
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE 
      response = http.request(request) 


     else 

      response = http.request(request) 
      response.body 
      #response = Net::HTTP.get_response(uri) 
     end 


     if response.code == '200' 

      code = response.code 
      puts "#{mMethod}: - Test passed! Response code: #{response.code}" 
      rHash[nKey] = code 

      #puts "#{rHash}" 
     else 
      code = response.code 
      puts "#{mMethod}: - Test failed! Response code: #{response.code}" 
      rHash[nKey] = code 
      #puts "#{rHash}" 



     end 
     return rHash 
    end 

我不知道我在做什麼錯得到這個錯誤。如果任何人都可以提供幫助,那會很棒。如果您需要更多代碼,請讓我知道。

+0

是什麼'uri.host'和'uri.port'? – Thomas

+0

我正在傳遞一個'URL',它是:'www.myurl.more.com/service/something?expand=something(。(this))&that = something'。我假設'URI = URI.parse(URI.encode(url))'函數解析出來。我想我可以記錄下來,看看裏面究竟有什麼? – BlackHatSamurai

+0

'uri.host' = myurl.more.com&'uri.port' = 80 – BlackHatSamurai

回答

0

事實證明應該是地址:https://www.myurl.more.com/service/something?expand=something(.(this))&that=something毋寧說:http://www.myurl.more.com/service/something?expand=something(.(this))&that=something

相關問題