HTTP调用不同的行为在当地VS AWS - 是红宝石或AWS? [英] HTTP calls behave different locally vs AWS - is it ruby or AWS?

查看:223
本文介绍了HTTP调用不同的行为在当地VS AWS - 是红宝石或AWS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,一个API我正在写。该API已经使其他服务和时间HTTP GET请求在某些situations-另一个服务被关闭/可达在大多数情况下。

我想在AWS上完全运行的系统,但在那里运行的API时,我经常得到超时试图访问同一实例的服务。该API是用红宝石+辛纳屈;我从来没有问题,它的蟒蛇predecessor。如果我卷曲的URL,其​​他服务在AWS实例命令行中,我从来没有超时。当我在本地运行的API(AWS上的其他服务),它工作得很好,每一次。

起初,我想这可能是HTTP库我using-网/ HTTP,这被证明是有问题的,甚至在本地。开关打开-URI或休息客户端修复了所有当地的问题,但是当我运行在AWS上我仍然得到超时的时间20%。

这个API是红宝石+采用开放式的URI做http请求西纳特拉。其他的服务或者是红宝石+西纳特拉或Java。我在32位的亚马逊Linux的小实例中运行,红宝石1.9.3,Java 1.6的;我的本地机的Mac雪豹红宝石1.9.3和Java 1.6为好。

任何意见或提示,以进一步缩小可能发生的事?


更新:!?我的大西纳特拉的应用程序和小屈的应用程序不同的行为

我的西纳特拉的应用程序的测试版本叫我的Java服务,在AWS上都运行......正常工作。

 需要'rubygems的'
要求URI
需要开放-URI
要求辛纳特拉

设置:端口,6969

得到'/跆拳道做
  XID = PARAMS [:XID]
  状态= PARAMS [:状态]
  service_addr ='http://prod.myserver.com
  摆脱='XXX'
  JSON = "{\"state\":\"#{state}\",\"sid\":\"0xac99d8929a89e6c01b56378336dec3a8L\",\"m\":\"set\",\"rid\":\"#{rid}\",\"id\":\"#{xid}\"}"

  ParamStr这= URI.escape(RID =#{}摆脱和ID =#{XID}&放大器; JSON =#{} JSON)
  响应=开(service_addr +?+ ParamStr这)
  状态= response.status [0]
  身体= response.read

  体
结束
 

大版本,与机架+作为一个更好的结构化西纳特拉的应用程序运行失败... + 20%的时间!

 要求URI
需要开放-URI

一流的MyApp<西纳特拉::基地

  得到'/跆拳道做
    XID = PARAMS [:XID]
    状态= PARAMS [:状态]
    service_addr ='http://prod.myserver.com
    摆脱='XXX'
    JSON = "{\"state\":\"#{state}\",\"sid\":\"0xac99d8929a89e6c01b56378336dec3a8L\",\"m\":\"set\",\"rid\":\"#{rid}\",\"id\":\"#{xid}\"}"

    ParamStr这= URI.escape(RID =#{}摆脱和ID =#{XID}&放大器; JSON =#{} JSON)
    响应=开(service_addr +?+ ParamStr这)
    状态= response.status [0]
    身体= response.read

    体
  结束

结束
 


更新2:使用mechanize-总是网关超时详细的错误读

对于简单的版本,它的作品每一次(无超时)。对于复杂的版本,这里有读数与机械化工作时,并没有。

在它的工作原理:

 我,[2012-05-22T22:45:53.267464#11610]信息 - :网:: HTTP ::获取:/? ###大长GET海峡
研发,[2012-05-22T22:45:53.267587#11610] DEBUG  - :请求标题:接受=> * / *
研发,[2012-05-22T22:45:53.267630#11610] DEBUG  - :请求标题:用户代理=>机械化/ 2.5.1的Ruby / 1.9.3p125(http://github.com/tenderlove/mechanize/)
研发,[2012-05-22T22:45:53.267676#11610] DEBUG  - :请求标题:接受编码=> GZIP,放气,身份
研发,[2012-05-22T22:45:53.267713#11610] DEBUG  - :请求标题:接收字符集=> ISO-8859-1,utf-8的; Q = 0.7,*; Q = 0.7
研发,[2012-05-22T22:45:53.267750#11610] DEBUG  - :请求标题:接受语言=> EN-US,EN; Q = 0.5
研发,[2012-05-22T22:45:53.267787#11610] DEBUG  - :请求标题:主机=> prod.pixieplug.com:9001
我,[2012-05-22T22:45:53.341814#11610]信息 - :状态:网:: HTTPOK 1.1 200 OK
研发,[2012-05-22T22:45:53.341916#11610] DEBUG  - :响应头:内容类型=>应用程序/ JSON的;字符集= ISO-8859-1
研发,[2012-05-22T22:45:53.341962#11610] DEBUG  - :响应头:传输编码=>分块
研发,[2012-05-22T22:45:53.342009#11610] DEBUG  - :响应头:服务器=>码头(8.0.y.z-快照)
研发,[2012-05-22T22:45:53.342137#11610] DEBUG  - :读取167个字节(167个)
98.247.240.63  -   -  [22 /月/ 2012 22点45分53秒]?GET /跆拳道XID = 00:00:00:00:00:17安培;状态= 255 HTTP / 1.1200 167 0.0777
 

当它不:

 我,[2012-05-22T22:46:23.665908#11610]信息 - :网:: HTTP ::获取:/#长PARAMS的名单?
研发,[2012-05-22T22:46:23.666014#11610] DEBUG  - :请求标题:接受=> * / *
研发,[2012-05-22T22:46:23.666053#11610] DEBUG  - :请求标题:用户代理=>机械化/ 2.5.1的Ruby / 1.9.3p125(http://github.com/tenderlove/mechanize/)
研发,[2012-05-22T22:46:23.666090#11610] DEBUG  - :请求标题:接受编码=> GZIP,放气,身份
研发,[2012-05-22T22:46:23.666125#11610] DEBUG  - :请求标题:接收字符集=> ISO-8859-1,utf-8的; Q = 0.7,*; Q = 0.7
研发,[2012-05-22T22:46:23.666161#11610] DEBUG  - :请求标题:接受语言=> EN-US,EN; Q = 0.5
研发,[2012-05-22T22:46:23.666233#11610] DEBUG  - :请求标题:主机=> prod.pixieplug.com:9001
我,[2012-05-22T22:46:28.675045#11610]信息 - :状态:网:: HTTPGatewayTimeOut 1.1 504网关超时
研发,[2012-05-22T22:46:28.675156#11610] DEBUG  - :响应头:内容类型=>应用程序/ JSON的;字符集= ISO-8859-1
研发,[2012-05-22T22:46:28.675195#11610] DEBUG  - :响应头:传输编码=>分块
研发,[2012-05-22T22:46:28.675232#11610] DEBUG  - :响应头:服务器=>码头(8.0.y.z-快照)
研发,[2012-05-22T22:46:28.675332#11610] DEBUG  - :读48个字节(48个)
机械化::响应codeError  -  504 =>网:: HTTPGatewayTimeOut为http://prod.pixieplug.com:9001/?#一长串PARAMS的 - 未处理的回应:
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:304:in'取'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/mechanize-2.5.1/lib/mechanize.rb:407:in'得到'
    /home/ec2-user/elphi-api/routes/sandbox.rb:15:in`块与<类:MyApp的>
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:1212:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:1212:in`块编译!
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in`[]'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in`块(3级)的路线!
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:801:in`route_eval
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in`块(2级)的路线!
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:822:in`块process_route
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in'抓'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in`process_route
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:784:in`块的路线!
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in`每个
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in'的路线!
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:886:in`调度!
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in`块的来电!
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in`块调用
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in'抓'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in'调用'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in'呼!
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:705:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in`上下文
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/logger.rb:15:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/head.rb:9:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/showexceptions.rb:21:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/lint.rb:48:in`_call
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/lint.rb:36:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/showexceptions.rb:24:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/chunked.rb:43:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/content_length.rb:14:in'呼叫'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:80:in`块pre_process
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:78:in'抓'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:78:in`pre_process
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:53:in'过程'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:38:in`receive_data
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in`run_machine
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in'运行'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/backends/base.rb:61:in'开始'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/server.rb:159:in'开始'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in'运行'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/server.rb:265:in'开始'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/server.rb:137:in'开始'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/bin/rackup:4:in`<顶(必填)>
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/bin/rackup:19:in'负荷'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/bin/rackup:19:in`<主>
98.247.240.63  -   -  [22 /月/ 2012 22时46分28秒]?GET /跆拳道XID = 00:00:00:00:00:17安培;状态= 255 HTTP / 1.1500 157221 5.1385
 

解决方案

这是一个奇怪的看的要求,通常是JSON数据进去后身体没有查询字符串。让我们尝试使用机械化,因为它提供了大量的调试信息,当您使用一个记录器,也许,这将有助于你看到问题所在。稍微重构code:

 要求西纳特拉/基地
需要'机械化'
需要'记录'
要求JSON

类MYAPP<西纳特拉::基地

  剂= Mechanize.new
  AGENT.log = Logger.new $标准输出

  得到'/跆拳道做
    RID,SID,XID,国家='XXX','0xac99d8929a89e6c01b56378336dec3a8L',则params [:XID],则params [:状态]
    service_addr ='http://prod.myserver.com/
    JSON = {'状态'=>状态,SID=> SID,'M'=> '设置','摆脱'=>摆脱,'身份证'=> XID} .to_json
    响应= AGENT.get service_addr,{:RID => RID,:ID => XID,:JSON => JSON}
    response.body
  结束

结束
 

I have a weird problem with an API I'm writing. The API has makes http get requests to other services and times out in certain situations- another service being off/unreachable in most cases.

I'm trying to run the system entirely on AWS, but when running the API on there I get frequent timeouts trying to access services on the same instance. The API is written in ruby+sinatra; I never had problems with its python predecessor. If I curl the url for other services from the AWS instance command line, I never get timeouts. When I run the API locally (other services on AWS), it works fine, every single time.

Initially I thought it might be the http library I was using- net/http, which turned out to be problematic even locally. Switching to open-uri or rest-client fixed all local problems, but when I run on AWS I still get timeouts 20% of the time.

The API is ruby+sinatra using open-uri to do http requests. The other services are either ruby+sinatra or java. I'm running on a 32-bit Amazon Linux small instance, ruby 1.9.3, java 1.6; my local machine is Mac with Snow Leopard with ruby 1.9.3 and java 1.6 as well.

Any ideas or tips to further narrow down what might be happening?


UPDATE: My big sinatra app and little sinatra app behave differently!?

The test version of my sinatra app to call my java service, both running on AWS... works fine.

require 'rubygems'
require 'uri'
require 'open-uri'
require 'sinatra'

set :port, 6969

get '/wtf' do
  xid = params[:xid]
  state = params[:state]
  service_addr = 'http://prod.myserver.com'
  rid = 'xxx'
  json = "{\"state\":\"#{state}\",\"sid\":\"0xac99d8929a89e6c01b56378336dec3a8L\",\"m\":\"set\",\"rid\":\"#{rid}\",\"id\":\"#{xid}\"}"

  paramStr = URI.escape("rid=#{rid}&id=#{xid}&json=#{json}")
  response = open(service_addr+"?"+paramStr)
  status = response.status[0]
  body = response.read

  body
end

The big version, running with Rack + as a better structured sinatra app... fails 20+% of the time!

require 'uri'
require 'open-uri'

class MyApp < Sinatra::Base

  get '/wtf' do
    xid = params[:xid]
    state = params[:state]
    service_addr = 'http://prod.myserver.com'
    rid = 'xxx'
    json = "{\"state\":\"#{state}\",\"sid\":\"0xac99d8929a89e6c01b56378336dec3a8L\",\"m\":\"set\",\"rid\":\"#{rid}\",\"id\":\"#{xid}\"}"

    paramStr = URI.escape("rid=#{rid}&id=#{xid}&json=#{json}")
    response = open(service_addr+"?"+paramStr)
    status = response.status[0]
    body = response.read

    body
  end

end


UPDATE 2: Detailed error readout using mechanize- always a gateway timeout

For the simple version, it works every time (no timeouts). For the complicated version, here are readouts with mechanize when it works, and doesn't.

When it works:

I, [2012-05-22T22:45:53.267464 #11610]  INFO -- : Net::HTTP::Get: /? ### big long get str
D, [2012-05-22T22:45:53.267587 #11610] DEBUG -- : request-header: accept => */*
D, [2012-05-22T22:45:53.267630 #11610] DEBUG -- : request-header: user-agent => Mechanize/2.5.1 Ruby/1.9.3p125 (http://github.com/tenderlove/mechanize/)
D, [2012-05-22T22:45:53.267676 #11610] DEBUG -- : request-header: accept-encoding => gzip,deflate,identity
D, [2012-05-22T22:45:53.267713 #11610] DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
D, [2012-05-22T22:45:53.267750 #11610] DEBUG -- : request-header: accept-language => en-us,en;q=0.5
D, [2012-05-22T22:45:53.267787 #11610] DEBUG -- : request-header: host => prod.pixieplug.com:9001
I, [2012-05-22T22:45:53.341814 #11610]  INFO -- : status: Net::HTTPOK 1.1 200 OK
D, [2012-05-22T22:45:53.341916 #11610] DEBUG -- : response-header: content-type => application/json;charset=ISO-8859-1
D, [2012-05-22T22:45:53.341962 #11610] DEBUG -- : response-header: transfer-encoding => chunked
D, [2012-05-22T22:45:53.342009 #11610] DEBUG -- : response-header: server => Jetty(8.0.y.z-SNAPSHOT)
D, [2012-05-22T22:45:53.342137 #11610] DEBUG -- : Read 167 bytes (167 total)
98.247.240.63 - - [22/May/2012 22:45:53] "GET /wtf?xid=00:00:00:00:00:17&state=255 HTTP/1.1" 200 167 0.0777

When it doesn't:

I, [2012-05-22T22:46:23.665908 #11610]  INFO -- : Net::HTTP::Get: /?# long list of params
D, [2012-05-22T22:46:23.666014 #11610] DEBUG -- : request-header: accept => */*
D, [2012-05-22T22:46:23.666053 #11610] DEBUG -- : request-header: user-agent => Mechanize/2.5.1 Ruby/1.9.3p125 (http://github.com/tenderlove/mechanize/)
D, [2012-05-22T22:46:23.666090 #11610] DEBUG -- : request-header: accept-encoding => gzip,deflate,identity
D, [2012-05-22T22:46:23.666125 #11610] DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
D, [2012-05-22T22:46:23.666161 #11610] DEBUG -- : request-header: accept-language => en-us,en;q=0.5
D, [2012-05-22T22:46:23.666233 #11610] DEBUG -- : request-header: host => prod.pixieplug.com:9001
I, [2012-05-22T22:46:28.675045 #11610]  INFO -- : status: Net::HTTPGatewayTimeOut 1.1 504 Gateway Timeout
D, [2012-05-22T22:46:28.675156 #11610] DEBUG -- : response-header: content-type => application/json;charset=ISO-8859-1
D, [2012-05-22T22:46:28.675195 #11610] DEBUG -- : response-header: transfer-encoding => chunked
D, [2012-05-22T22:46:28.675232 #11610] DEBUG -- : response-header: server => Jetty(8.0.y.z-SNAPSHOT)
D, [2012-05-22T22:46:28.675332 #11610] DEBUG -- : Read 48 bytes (48 total)
Mechanize::ResponseCodeError - 504 => Net::HTTPGatewayTimeOut for http://prod.pixieplug.com:9001/?# long list of params  -- unhandled response:
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:304:in `fetch'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/mechanize-2.5.1/lib/mechanize.rb:407:in `get'
    /home/ec2-user/elphi-api/routes/sandbox.rb:15:in `block in <class:MyApp>'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:1212:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:1212:in `block in compile!'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `[]'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `block (3 levels) in route!'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:801:in `route_eval'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `block (2 levels) in route!'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:822:in `block in process_route'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in `catch'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in `process_route'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:784:in `block in route!'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in `each'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in `route!'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:886:in `dispatch!'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `block in call!'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `block in invoke'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `catch'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `invoke'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `call!'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/base.rb:705:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/logger.rb:15:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.2/lib/sinatra/showexceptions.rb:21:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/lint.rb:48:in `_call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/lint.rb:36:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/showexceptions.rb:24:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/chunked.rb:43:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/content_length.rb:14:in `call'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:80:in `block in pre_process'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:78:in `catch'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:78:in `pre_process'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:53:in `process'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:38:in `receive_data'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/backends/base.rb:61:in `start'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/server.rb:159:in `start'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/server.rb:265:in `start'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/server.rb:137:in `start'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/bin/rackup:4:in `<top (required)>'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/bin/rackup:19:in `load'
    /home/ec2-user/.rvm/gems/ruby-1.9.3-p125/bin/rackup:19:in `<main>'
98.247.240.63 - - [22/May/2012 22:46:28] "GET /wtf?xid=00:00:00:00:00:17&state=255 HTTP/1.1" 500 157221 5.1385

解决方案

It's a strange looking request, usually json data goes in a post body not the query string. Let's try using mechanize because it gives lots of debug information when you use a logger and maybe that will help you see where the problem is. Slightly refactored code:

require 'sinatra/base'
require 'mechanize'
require 'logger'
require 'json'

class Myapp < Sinatra::Base

  AGENT = Mechanize.new
  AGENT.log = Logger.new $stdout

  get '/wtf' do
    rid, sid, xid, state = 'xxx', '0xac99d8929a89e6c01b56378336dec3a8L', params[:xid], params[:state]
    service_addr = 'http://prod.myserver.com/'
    json = {'state' => state, 'sid' => sid, 'm' => 'set', 'rid' => rid, 'id' => xid}.to_json
    response = AGENT.get service_addr, {:rid => rid, :id => xid, :json => json}
    response.body
  end

end

这篇关于HTTP调用不同的行为在当地VS AWS - 是红宝石或AWS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆