En tâtonnant, j'arrive à :

# encoding : utf-8

require 'base64'
require 'rubygems'
require 'httparty'

class Timestamp

  # SOURCE : https://www.universign.eu/fr/web-services

=begin

  static InputStream doTsp(String login, String pwd, String hash, String
algo)
          throws Exception
        {
          URLConnection conn = new URL("https://ws.universign.eu/tsa/post/
").openConnection();
          conn.setDoOutput(true);
          conn.setDoInput(true);
          String authString = login + ":" + pwd;
          String authStringEnc = Base64.encode(authString);
          conn.setRequestProperty("Authorization", "Basic " +
authStringEnc);

          OutputStream out = conn.getOutputStream();
          String params = "hashAlgo=" + URLEncoder.encode(algo, "UTF-8") +
"&hashValue="
              + URLEncoder.encode(hash, "UTF-8") + "&withCert=" +
URLEncoder.encode("false", "UTF-8");
          out.write(params.getBytes("UTF-8"));
          out.flush();

          return conn.getInputStream();
        }
=end
  include HTTParty
  #hash = "test pour universign"
  def self.doTsp(login="toto",
pwd="titi",hash="cb493b4f9c0bda24f0443a11dad75b3a04aec8b78440c193eea4857e4d6f8725",algo="SHA256")
    authString = login + ":" + pwd
    authStringEnc = Base64.encode64(authString)
    base_uri "https://ws.universign.eu/tsa/post/";
    headers "Authorization" => "Basic " + authStringEnc
    params = {"hashAlgo" => CGI::escape(algo), "hashValue" =>
CGI::escape(hash), "withCert" => CGI::escape("false") }
    post "/", :query => params , :body => headers
  end

end

Je pense être proche du but car j'obtiens :
=> #<HTTParty::Response:0x8 @parsed_response=nil,
@response=#<Net::HTTPUnauthorized 401 J readbody=true>,
@headers={"cache-control"=>["no-cache"], "pragma"=>["no-cache"],
"content-type"=>["application/octet-stream"],
"transfer-encoding"=>["chunked"], "www-authenticate"=>["Basic
realm=\"Universign\""]}>
avec ce login et mot de passe.
Mais aucune réponse avec les bons login/mot de passe. Si tout va bien, il
ne me manque que l'équivalent de conn.getInputStream() que je n'ai pas
trouvé.

Le 21 novembre 2011 17:31, Bruno Muscolino <[email protected]> a écrit :

> J'utilise ce même code pour me connecter aux WS de ma banque.
>
> :)
>
> Have fun
> Bruno
>
> On Nov 21, 2011, at 11:29 AM, Frédérick Sauvage wrote:
>
> Oui je cherches à utiliser leur WebService ... je vais essayer de me
> débrouiller avec cela et la doc de httparty tant bien que mal
>
> Le 21 novembre 2011 17:10, Bruno Muscolino <[email protected]> a écrit
> :
>
>> En gros ce que tu cherches a faire c'est de te connecter sur leur page et
>> utiliser leur WebServices?
>>
>> En ruby: (voir doc do httparty pour determiner ou non si tu veux qqch
>> dans la hash query)
>>
>> require 'rubygems'
>> require 'httparty'
>>
>> class LoginSomeWhere
>>  include HTTParty
>>  base_uri "https://YOURURL.COM";
>>  headers "content-type" => "application/x-www-form-urlencoded"
>>
>>  def self.login username, password
>>    post "/", :query => {  }, :body => { :username => username, :password
>> => password }
>>  end
>> end
>>
>> puts LoginSomeWhere.login "username", "password"
>>
>> Ca
>>
>> On Nov 21, 2011, at 10:06 AM, Frédérick Sauvage wrote:
>>
>> > Bonjour,
>> >
>> > Cherchant à créer un sceau d'horodatage via Universign, je me retrouve
>> > face à 3 codes pour réaliser cela ... évidemment nulle trace de Ruby.
>> > Je cherche actuellement comment m'adapter au Ruby (en partant du Java
>> > que je maitrise mieux), mais je rencontre des difficultés.
>> >
>> > Une bonne âme pourrait-elle m'aider ?
>> >
>> > Voici les différents codes :
>> >
>> > En Python :
>> >
>> >      #!/usr/bin/python
>> >
>> >      import urllib;
>> >      import urllib2;
>> >      import hashlib;
>> >      import base64;
>> >
>> >      # first we construct the parameters for the request
>> >      data = {};
>> >      data['hashAlgo'] = "SHA256";
>> >      data['withCert'] = "true";
>> >      data['hashValue'] = hashlib.sha256(dataToTimestamp).hexdigest();
>> >      params = urllib.urlencode(data);
>> >
>> >      # basic HTTP authentication is needed to access this service
>> >      headers = {};
>> >      auth = base64.encodestring(username + ":" + password);
>> >      headers["Authorization"] = "Basic " + auth;
>> >
>> >      # then the request itself
>> >      request = urllib2.Request("https://ws.universign.eu/tsa/post/";,
>> > params, headers);
>> >
>> >      # all is ready, the request is made
>> >      response = urllib2.urlopen(request);
>> >      tsp = response.read();
>> >
>> >
>> >
>> > En PHP :
>> >
>> >      $hashedDataToTimestamp = hash('sha256', $dataToTimestamp);
>> >      $dataToSend = array ('hashAlgo' => 'SHA256', 'withCert' =>
>> > 'true', 'hashValue' => $hashedDataToTimestamp);
>> >      $dataQuery = http_build_query($dataToSend);
>> >      $context_options = array (
>> >              'http' => array (
>> >                  'method' => 'POST',
>> >                  'header'=> "Content-type: application/x-www-form-
>> > urlencoded\r\n"
>> >                   ."Content-Length: " . strlen($dataQuery) . "\r\n"
>> >                   ."Authorization: Basic ".base64_encode($login.':'.
>> > $password)."\r\n",
>> >                  'content' => $dataQuery
>> >                )
>> >            );
>> >
>> >      $context = stream_context_create($context_options);
>> >      $fp = fopen("https://ws.universign.eu/tsa/post/";, 'r', false,
>> > $context);
>> >      $tsp = stream_get_contents($fp);
>> >
>> >
>> >
>> > En Java :
>> >
>> >      static InputStream doTsp(String login, String pwd, String hash,
>> > String algo)
>> >        throws Exception
>> >      {
>> >        URLConnection conn = new URL("https://ws.universign.eu/tsa/
>> > post/").openConnection();
>> >        conn.setDoOutput(true);
>> >        conn.setDoInput(true);
>> >        String authString = login + ":" + pwd;
>> >        String authStringEnc = Base64.encode(authString);
>> >        conn.setRequestProperty("Authorization", "Basic " +
>> > authStringEnc);
>> >
>> >        OutputStream out = conn.getOutputStream();
>> >        String params = "hashAlgo=" + URLEncoder.encode(algo, "UTF-8")
>> > + "&hashValue="
>> >            + URLEncoder.encode(hash, "UTF-8") + "&withCert=" +
>> > URLEncoder.encode("false", "UTF-8");
>> >        out.write(params.getBytes("UTF-8"));
>> >        out.flush();
>> >
>> >        return conn.getInputStream();
>> >      }
>> >
>> >
>> > Merci d'avance,
>> >    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]
>
>
>
>
> --
> 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]
>



-- 
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]

Répondre à