标签: net-http

干净安装后持久的Ruby segfaulting

当使用Koala gem通过HTTP进行通信时,Ruby会保持segfaulting:

/Users/pawel/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:799: [BUG] Segmentation fault
Run Code Online (Sandbox Code Playgroud)

我尝试过以下方法:

  • which -a ruby通过MacPorts 运行显示多个Rubies.所以我删除了那些并再次运行相同的命令返回/usr/bin/ruby
  • 我删除了PostgreSQL的MacPorts版本,并用Homebrew安装了它(使用MacPorts,它安装了自己的OpenSSL版本)
  • 运行openssl version回报OpenSSL 1.0.0g 18 Jan 2012
  • 我从RVM中删除了Ruby 1.9.3并尝试了下面没有用的Luciano方法.
  • 我也试着重新安装1.9.3从RVM并指定--with-openssl-dir=/opt/local以来which openssl回报/opt/local/bin/openssl
  • 我重新安装了RVM(它现在是版本1.10.2 /Users/pawel/.rvm/bin/rvm)
  • 我已经升级到Ruby 1.9.3-p125并且还尝试过1.9.2
  • 我按照这里的说明操作:http://www.christopherirish.com/2011/09/02/ruby-1-9-2-segmentation-fault-and-openssl/(实际上是我上面的步骤).我也在这里读过克里斯托弗的上一篇文章.
  • 在我的项目目录中,当我运行以下内容时,我得到了预期的0.:

    ruby -rubygems -e" require 'eventmachine'; require 'openssl' "; echo $?

  • 我试过,sudo port -f deactivate openssl但是当我尝试启动Rails服务器时,我得到了Library not loaded: /opt/local/lib/libssl.1.0.0.dylib

关于我还能尝试什么,或者我错过了什么,我需要更多的想法.

ruby openssl segmentation-fault ruby-on-rails-3 net-http

3
推荐指数
1
解决办法
1682
查看次数

为什么我得到Net :: HTTP"请求路径为空"错误?

我正在使用Net :: HTTP发出HTTP请求.我收到错误"HTTP请求路径为空",但我强烈认为它不是.代码如下:

REQUEST_IP = "localhost"
REQUEST_PORT = "8081"
REQUEST_PATH = "myweb/rest"

def customServiceMailAndMessageRequest user_id, message

  url = 'http://' + REQUEST_IP + ":" + REQUEST_PORT + "/" + REQUEST_PATH + '/users/' + user_id + '/messages/sendMailAndMessage?message=' + message
  uri = URI(url)

  request = Net::HTTP::Get.new(uri.path)
  request['Content-Type'] = 'application/json'
  request['Accept'] = 'application/json'

  response = Net::HTTP.new(uri.host,uri.port) do |http|
    http.request(request)
  end

  puts response

end
Run Code Online (Sandbox Code Playgroud)

错误是:

/usr/lib/ruby/1.8/net/http.rb:1478:in `initialize': HTTP request path is empty (ArgumentError)
    from /usr/lib/ruby/1.8/net/http.rb:1596:in `initialize'
Run Code Online (Sandbox Code Playgroud)

谁能指出我的错误?

ruby net-http

3
推荐指数
1
解决办法
5446
查看次数

在Ruby中发出HEAD请求

我是ruby的新手,从python背景我想对URL发出请求并查看一些信息,比如文件是否存在于服务器和时间戳,etag等等,我无法完成红宝石.

在Python中:

import httplib2
print httplib2.Http().request('url.com/file.xml','HEAD')
Run Code Online (Sandbox Code Playgroud)

在Ruby中:我试过这个并抛出一些错误

require 'net/http'

Net::HTTP.start('url.com'){|http|
   response = http.head('/file.xml')
}
puts response


SocketError: getaddrinfo: nodename nor servname provided, or not known
    from /Users/comcast/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:877:in `initialize'
    from /Users/comcast/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:877:in `open'
    from /Users/comcast/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:877:in `block in connect'
    from /Users/comcast/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/timeout.rb:51:in `timeout'
    from /Users/comcast/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:876:in `connect'
    from /Users/comcast/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:861:in `do_start'
    from /Users/comcast/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:850:in `start'
    from /Users/comcast/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:582:in `start'
    from (irb):2
    from /Users/comcast/.rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in `<main>'
Run Code Online (Sandbox Code Playgroud)

ruby net-http

3
推荐指数
2
解决办法
6609
查看次数

ruby net/http`read_body':Net :: HTTPOK#read_body被调用两次(IOError)

我正在使用net/http库调用read_body两次(IOError).我正在尝试下载文件并有效地使用http会话.寻求一些帮助或建议来解决我的问题.从我的调试消息中,它在我记录响应代码时出现,readbody = true.这就是为什么当我尝试以块的形式编写大文件时read_body被读取两次?

D, [2015-04-12T21:17:46.954928 #24741] DEBUG -- : #<Net::HTTPOK 200 OK readbody=true>
I, [2015-04-12T21:17:46.955060 #24741]  INFO -- : file found at http://hidden:8080/job/project/1/maven-repository/repository/org/project/service/1/service-1.zip.md5
/usr/lib/ruby/2.2.0/net/http/response.rb:195:in `read_body': Net::HTTPOK#read_body called twice (IOError)
    from ./deploy_application.rb:36:in `block in get_file'
    from ./deploy_application.rb:35:in `open'
    from ./deploy_application.rb:35:in `get_file'
    from ./deploy_application.rb:59:in `block in <main>'
    from ./deploy_application.rb:58:in `each'
    from ./deploy_application.rb:58:in `<main>'
Run Code Online (Sandbox Code Playgroud)
require 'net/http'
require 'logger'

STAMP = Time.now.utc.to_i

@log = Logger.new(STDOUT)

# project , build, service remove variables above
project = "project"
build = "1"
service = "service"
version = …
Run Code Online (Sandbox Code Playgroud)

ruby net-http

3
推荐指数
1
解决办法
1686
查看次数

调整Nokogiri连接的超时

为什么nokogiri在服务器繁忙时等待几秒钟(3-5)并且我逐个请求页面,但是当这些请求处于循环中时,nokogiri不会等待并抛出超时消息.我正在使用超时阻止包裹请求,但nokogiri根本不等待那个时间.有关此的任何建议程序?

# this is a method from the eng class
def get_page(url,page_type)
 begin
  timeout(10) do
    # Get a Nokogiri::HTML::Document for the page we’re interested in...
    @@doc = Nokogiri::HTML(open(url))
  end
 rescue Timeout::Error
  puts "Time out connection request"
  raise
  end
end

 # this is a snippet from the main app calling eng class
 # receives a hash with urls and goes throgh asking one by one
 def retrieve_in_loop(links)
  (0..links.length).each do |idx|
    url = links[idx]
    puts "Visiting link #{idx} of #{links.length}"
    puts "link: …
Run Code Online (Sandbox Code Playgroud)

ruby timeout open-uri nokogiri net-http

2
推荐指数
1
解决办法
3018
查看次数

如何在不等待Ruby响应的情况下发出HTTP请求

我只是想从我的Rails控制器内部命中服务器,但不等待响应.这可能吗?(没有启动其他线程我出于性能原因无法做到这一点)

ruby net-http

2
推荐指数
1
解决办法
4671
查看次数

如何使用 Faraday gem 检索response.URL?

我正在使用Faraday来检查损坏的链接,并且我想检索我正在查询的链接的response.URL,但是,我无法找到任何文档和示例来执行此操作。

我可以使用Javascript的Fetch API(Response.url:https: //developer.mozilla.org/en-US/docs/Web/API/Response/url )在前端执行此操作,但这不是一个选项现在,因为我需要仅使用法拉第在后端执行此操作。

法拉第有可能做到这一点吗?如果是这样,我该如何实施?或者请指出我正确的文档。

ruby rubygems net-http faraday

2
推荐指数
1
解决办法
1320
查看次数

如何使用net/http发布xml数据,网址中也包含数据

我正在使用api,它要求我将xml发布到url,例如someapi.com?userID = 123.到目前为止,我已经尝试过这个(假设xml已经在xml变量中编写):

url = URI.parse('http://www.someapi.com/process_leads.asp')
request = Net::HTTP::Post.new(url.path)
request.content_type = 'text/xml'
request.body = xml
request.set_form_data({'userID' => '1204'}, ';')
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
Run Code Online (Sandbox Code Playgroud)

我想弄清楚我是否可以将userID作为表单数据但是也可以发布xml?我基本上应该将xml发布到http://www.someapi.com/process_leads.asp?userID=1204.那可能吗?

xml post ruby-on-rails http net-http

1
推荐指数
1
解决办法
3382
查看次数

如果它保持超时,我如何使用net/http执行while语句?

我有以下代码:

require 'rubygems'
require 'net/http'
require 'uri'
url = URI.parse('http://servername.tld/up.txt')
response = Net::HTTP.get_response(url)

@yes = response.body
until @yes == "yes"
  puts "It's down"
end
Run Code Online (Sandbox Code Playgroud)

内容/up.txt

但是,当它(即服务器托管up.txt)关闭时,它会保持超时,这样:

/home/jrg/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:644:in`初始化':拒绝连接 - 连接(2)(错误:: ECONNREFUSED)

相关,但没有帮助: 为什么我在Rails中使用'net/http'获得"Errno :: ECONNREFUSED"?

我是否需要考虑使用其他东西Net::HTTP

ruby net-http

1
推荐指数
1
解决办法
2717
查看次数

如何设置Header with Net :: Http for Goo.gl Shorten服务?

就像在API Goo.gl中描述一样

Manualy卷曲工作完美:

curl https://www.googleapis.com/urlshortener/v1/url \
    -H 'Content-Type: application/json' \
    -d '{"longUrl": "http://www.rubyinside.com/"}'
Run Code Online (Sandbox Code Playgroud)

我试图在Net :: Http中做这个时:

require "net/https"
require "uri"
uri = URI.parse("https://www.googleapis.com/urlshortener/v1/url")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.path)
request["Content-Type"] = "application/json"
request.set_form_data({"longUrl" => "http://www.rubyinside.com/"})
response = http.request(request)
puts response.body
Run Code Online (Sandbox Code Playgroud)

但是响应失败了:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "parseError",
    "message": "This API does not support parsing form-encoded input."
   }
  ],
  "code": 400,
  "message": "This API does not support parsing form-encoded input." …
Run Code Online (Sandbox Code Playgroud)

ruby goo.gl net-http

1
推荐指数
1
解决办法
2744
查看次数

如何在Golang中复制http.Get(url)请求的响应

我正在尝试使用resp, err := http.Get(url)命令将响应写入文件以及使用相同的响应来提取链接。

使用将内容写入文件后resp.Write(f),如果resp.Body没有其他http.Get请求,就无法用于其他目的(来自上述url的响应)。

我试过了resp2 := bytes.NewBuffer(resp)。由于类型不匹配,因此会给出错误。我也尝试过复制。

go net-http

0
推荐指数
1
解决办法
3305
查看次数