簡體   English   中英

RAILS Quickbook oauth2將URL轉換為Net :: HTTP請求

[英]RAILS Quickbook oauth2 convert url to Net ::HTTP request

我需要將以下發布請求轉換為Rails Net::HTTP請求。

POST https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer HTTP/1.1 
Accept: application/json 
Authorization: Basic UTM0dVBvRDIwanp2OUdxNXE1dmlMemppcTlwM1d2NzRUdDNReGkwZVNTTDhFRWwxb0g6VEh0WEJlR3dheEtZSlVNaFhzeGxma1lXaFg3ZlFlRzFtN2szTFRwbw==
Content-Type: application/x-www-form-urlencoded
Host:oauth.platform.intuit.com
Body: grant_type=authorization_code&code=L3114709614564VSU8JSEiPkXx1xhV8D9mv4xbv6sZJycibMUI&redirect_uri=https://www.mydemoapp.com/oauth-redirect

我正在使用此文檔

https://developer.intuit.com/app/developer/qbpayments/docs/develop/authentication-and-authorization/oauth-2.0#exchange-code-for-refresh-and-access-tokens

為此,您可以使用Rails Net :: HTTP類本身。 嘗試,

require 'net/http'

url = URI.parse('https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer')
req = Net::HTTP::Post.new(url.to_s)
res = Net::HTTP.start(url.host, url.port) {|http|
  http.request(req)
}
puts res.body

有關更多詳細信息, 請參見

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM