application error Errno::ECONNREFUSED
尝试发送 HTTP 请求时出现错误。我正在使用Sinatra
,并在我的工作站上进行本地设置。这是错误:
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
我不确定我做错了什么来得到这个错误。如果有人可以提供帮助,那就太好了。如果您需要更多代码,请告诉我。