have fun:

# encoding : utf-8
require 'rubygems'
require 'base64'
require 'httparty'

class Timestamp
  include HTTParty
  base_uri "https://ws.universign.eu/tsa/";
  
  def self.doTsp(login, pwd, hashAlgo, hashValue, withCert)
    data = { :hashAlgo => hashAlgo, :hashValue => hashValue, :withCert => 
withCert }
    h = { "content-type" => "application/x-www-form-urlencoded", 
"authorization" => "Basic " + "#{Base64.encode64("#{login + ":" + pwd}")}"}
    return post("/post", :headers=> h, :body => data)
  end

end


hashValue = "cb493b4f9c0bda24f0443a11dad75b3a04aec8b78440c193eea4857e4d6f8725"
hashAlgo = "SHA256"
withCert = false

puts Timestamp.doTsp("username", "password", hashAlgo, hashValue, 
withCert).inspect


On Nov 22, 2011, at 6:23 AM, Frédérick Sauvage wrote:

> Finalement la console ajoute :
> 
> Errno::ETIMEDOUT: Connection timed out - connect(2)
>         from /usr/lib/ruby/1.9.1/net/http.rb:644:in `initialize'
>         from /usr/lib/ruby/1.9.1/net/http.rb:644:in `open'
>         from /usr/lib/ruby/1.9.1/net/http.rb:644:in `block in connect'
>         from /usr/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
>         from /usr/lib/ruby/1.9.1/timeout.rb:87:in `timeout'
>         from /usr/lib/ruby/1.9.1/net/http.rb:644:in `connect'
>         from /usr/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
>         from /usr/lib/ruby/1.9.1/net/http.rb:626:in `start'
>         from /usr/lib/ruby/1.9.1/net/http.rb:1160:in `request'
>         from /usr/lib/ruby/1.9.1/net/http.rb:970:in `post'
>         from /srv/lb-06/lb2_srv_web/lib/timestamp/lb_timestamp.rb:56:in 
> `doTsp'
>         from (irb):2
>         from 
> /var/lib/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands/console.rb:44:in 
> `start'
>         from 
> /var/lib/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands/console.rb:8:in 
> `start'
>         from 
> /var/lib/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:23:in `<top 
> (required)>'
>         from script/rails:6:in `require'
>         from script/rails:6:in `<main>'
> 
> Le 22 novembre 2011 12:21, Frédérick Sauvage <[email protected]> a 
> écrit :
> Bonjour
> 
> Nouvelles informations :
> 
> avec :
> 
> 
>     authString = login + ":" + pwd
>     url = "https://ws.universign.eu/tsa/post/";
>     puts url.to_s
>     uri = URI.parse(url)
>     puts uri.to_s
>     headers = {
>       'Content-Type' => 'application/x-www-form-urlencoded',
>       'Authorization' => "Basic #{Base64.encode64(authString).strip}",
>     }
>     params = {:hashAlgo=>algo,:hashValue=>hash, :withCert=>"false"};
>     puts params.to_s
>     http = Net::HTTP.new(uri.host)
>     puts http.to_s
>     post_data = params.map 
> {|k,v|"#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}" }.join("&")
>     puts post_data.to_s
>     resp, data = http.post(uri.path, post_data, headers)
>     puts resp.to_s
>     puts data.to_s
> 
>     return JSON.parse(data)
> 
> 
> J'obtiens :
> https://ws.universign.eu/tsa/post/
> https://ws.universign.eu/tsa/post/
> {:hashAlgo=>"SHA256", 
> :hashValue=>"cb493b4f9c0bda24f0443a11dad75b3a04aec8b78440c193eea4857e4d6f8725",
>  :withCert=>"false"}
> #<Net::HTTP:0x0000000308bfa8>
> hashAlgo=SHA256&hashValue=cb493b4f9c0bda24f0443a11dad75b3a04aec8b78440c193eea4857e4d6f8725&withCert=false
> 
> Puis ... rien. La console semble attendre une information.
> Ce code me fait tourner en bourrique.
> 
> Cordialement,
> 
> 
> 
> -- 
> SAUVAGE Frédéric
> 
> 
> -- 
> Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de 
> Google Groups.
> Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse 
> [email protected]
> Pour résilier votre abonnement envoyez un e-mail à l'adresse 
> [email protected]

-- 
Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de 
Google Groups.
Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse 
[email protected]
Pour résilier votre abonnement envoyez un e-mail à l'adresse 
[email protected]

Répondre à