- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试使用 Gnip PowerTrack API,这需要我使用基本身份验证连接到 JSON 的 HTTPS 流。我觉得这应该是相当微不足道的,所以我希望一些比我聪明的 rubyist 可以指出我明显的错误。
这是我的 ruby 1.9.3 代码的相关部分:
require 'eventmachine'
require 'em-http'
require 'json'
usage = "#{$0} <user> <password>"
abort usage unless user = ARGV.shift
abort usage unless password = ARGV.shift
GNIP_STREAMING_URL = 'https://stream.gnip.com:443/foo/bar/prod.json'
http = EM::HttpRequest.new(GNIP_STREAMING_URL)
EventMachine.run do
s = http.get(:head => { 'Authorization' => [user, password], 'accept' => 'application/json', 'Accept-Encoding' => 'gzip,deflate' }, :keepalive => true, :connect_timeout => 0, :inactivity_timeout => 0)
buffer = ""
s.stream do |chunk|
buffer << chunk
while line = buffer.slice!(/.+\r?\n/)
puts JSON.parse(line)
end
end
end
流连接(我的 Gnip 仪表板报告连接)但随后只是缓冲并且从不输出任何东西。事实上,它似乎从未进入 s.stream do..
block 。请注意,这是一个 GZip 编码流。
请注意,这是可行的:
curl --compressed -uusername $GNIP_STREAMING_URL
编辑:我确定这有点含蓄,但我不能给出任何登录凭据或实际 URL,所以不要问 ;)
编辑 #2:如果我能弄清楚如何对 URL 的凭据进行编码,yajl-ruby 可能会起作用(简单的 URL 编码似乎不起作用,因为我无法通过 Gnip 进行身份验证)。
编辑 #3:@rweald 发现 em-http 不支持流式 gzip,我在这里创建了一个 GitHub 问题。
编辑 #4:我已经在 em-http-request 中 fork 并修复了这个问题,你可以指向 my fork如果你想以这种方式使用 em-http。该补丁已合并到维护者的存储库中,并将在下一个版本中运行。
编辑 #5:我的修复已在 em-http-request 1.0.3 中发布,因此这应该不再是一个问题。
最佳答案
问题出在 em-http-request 中。如果你看 https://github.com/igrigorik/em-http-request/blob/master/lib/em-http/decoders.rb
你会注意到 GZIP 解压器不能做流式解压:( https://github.com/igrigorik/em-http-request/blob/master/lib/em-http/decoders.rb#L100
如果您希望能够使用 em-http-request 读取流,则需要修复底层流 gzip 问题
关于ruby - 具有基本身份验证和 gzip 的 em-http 流挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9346848/
我遇到了这个错误: java.lang.IllegalArgumentException: Removing a detached instance model.student 然后我在stackov
em在中是什么意思 ... 这是从 firefox 插件 install.rdf 文件中提取的。我很好奇 em 部分添加了什么。我在 Google 上也找不到解决方案。 最佳答案 em 是包含 des
在如下所示的脚本中 create queue one create queue two create topic three 如何评论一行? 最佳答案 我可以在工具本身或文档中找到注释。 您可以做的最
谁能解释一下为什么 Redis (redis-rb) 同步驱动程序直接在 EM.synchrony block 下工作,但不在 EM:Connection 内工作? 考虑下面的例子 EM.sy
在下面,我需要得到: String regex = "Item#: .*"; String content = "xxx Item#: something yyy"; Pattern pattern
em 和 % 在文本大小调整和固定宽度站点方面有什么区别?如果我使用 em 或 % 仅用于固定宽度站点中的文本大小调整,并且正文设置为 {body:font-size:100%} 在可访问性和移动设备
这两个 CSS 语句有什么区别: h1 em { color:#ddd; } 和 h1 > em { color:#ddd; } 据我所知他们做的是完全一样的事情(虽然根据我在 W3C 上读到的第一种
在CSS3 CSS Fonts Module Level 3 (candidate Oct 13) , 在第 2.3 节中有一个对“EM 盒”的引用和一个对“EM 单元”的引用。引用如下: [The
em.find(Enity.classs, Id) em.createQuery("SELECT e From Entity e WHERE e.Id=:id") 它们是等价的吗?如果不是,它们有何不
在 CSS 中,em 是一个基于文档字体大小的相对单位。那么,如果文档本身 的字体大小以em 为单位,那么em 到底是什么?假设我们说: body { font-size: 1em; }
有实体 /** * @ORM\Entity(repositoryClass="Some\Namspace\CustomRepository") * @ORM\Table(name="image_t
您好,我有一个关于 Doctrine 的快速问题以及 merge() 和 persist() 之间的区别 我有一个 NewsBuilder 类: 这需要一个新闻实体并检查它是否存在于数据库,如果存在,
我有下面的代码,想知道 JPA 如何知道保留此更新。我预计需要 em.merge() 才能执行更新。这真的安全吗? @Stateless class User { ... public
在 JPA 中,是否保证以下片段的事务语义(=从数据库的角度来看的效果)是相同的? 片段A EntityManager em = ... List workList = ... for(Work wo
我现在正在使用 EventMachine 玩了几天,恕我直言,它的学习曲线很陡;-) 我尝试通过触发回调中需要的 HttpHeaderCrawler.query() 来返回哈希。但是在这种情况下我得到
我有以下 HTML 代码: Hello World 我正在设计它的样式: h1 {font-size:100pt} 如何将此 100pt 转换为 EM 和 REM? 最佳答案 在 CSS 中, - p
我是 OpenCV 和 C++ 的新手,我正在尝试使用 OpenCV 中的高斯混合模型构建分类器。我弄清楚了它是如何工作的,并让它工作了……也许吧。我现在得到了这样的东西: 如果我在模型训练和保存后立
我们有一个 TIBCO EMS 解决方案,它在 2-4 服务器环境中使用内置服务器故障转移。如果 TIBCO 管理员将服务从一台 EMS 服务器故障转移到另一台,则连接应该会在 EMS 服务级别自动转
YUI 中的这一行 Reset CSS给我带来了麻烦: address,caption,cite,code,dfn,em,strong,th,var { font-style: normal;
我想并发下载网页,所以我找到了这些库, 但是我分不清em-synchrony和em-http-request的关系? 我查看了每个存储库的 github,但似乎所有示例都是关于自己的, 但是从一些文章
我是一名优秀的程序员,十分优秀!