2017-08-19 1 views
0

Ich verwende RestClient Juwel, unter meinem Befehl istRuby-POST-Anfrage mit Grunde Auth und mehrere Daten

curl -H 'Authorization: Basic ENCODED_CLIENT_CREDENTIALS' --data '[email protected]&password=test&grant_type=password&scope=user%20documents%20user%2Fdocumentsv2' https://api.com/oauth2/token 

Ich bin nicht dazu weiter unten über RestClient übersetzen ist mein Code:

access = RestClient::Request.new(
     :method => :post, 
     :url => 'https://api.com/oauth2/token', 
     :data => { 
      :username => 'xxxx', 
      :password => 'xxxx', 
      :grant_type => 'password' 
     }, 
     :headers => { 
      :Authorization => "Basic some_string", 
      :'Content-Type' => 'application/x-www-form-urlencoded' 
     } 
    ) 

Zeigt 400 ungültige Anfrage an. Kann jemand für diese Übersetzung helfen.

Dank

Antwort

0

Wrong auf dieser Linie unter

:data => { 
    :username => 'xxxx', 
    :password => 'xxxx', 
    :grant_type => 'password' 
}, 

Sie payload statt data wie unten verwenden:

:payload => { 
    :username => 'xxxx', 
    :password => 'xxxx', 
    :grant_type => 'password' 
}, 

Ich hoffe, dass Sie Hilfe.