0
相當新的這個發送POST請求被學習Ruby中的API。使用電子郵件服務的API在系統中創建用戶。帶HTTP頭
這是POST的例子:
POST http://localhost:8080/core/postgres-pages-xy/api/rest/v4/user/[email protected] HTTP/1.1
Authorization: Basic bWFzdGVyQGVuubXVjLmVjaXJjbGUuZGU6aDhuc3d1cnN0
User-Agent: curl/7.29.0
Host: localhost:8080
Proxy-Connection: Keep-Alive
Content-Type:application/json
Accept:application/json
Content-Length: 86
[{"name":"user.FirstName","value":"Stan"}, {"name":"user.LastName", "value":"Laurel"}]
我想我靠近(ISH)?在Ruby中希望有人能告訴我怎樣通過發送我的身份驗證。系統要求登錄標題不知道該怎麼做,將是一個電子郵件和密碼:
require 'uri'
require 'net/http'
uri = URI("https://site.com/api/rest/v4/user/[email protected]")
https = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.path)
request.basic_auth 'email', 'pass'
request["user.FirstName"] = 'Liam'
request["user.LastName"] = 'Coates'
response = https.request(request)
puts response
感謝您的反饋或學習。
我用,現在和更新我的代碼上面 - 我得上班就可以了,因爲我不知道這些錯誤是:/usr/lib/ruby/1.8/net/http.rb:564:in'初始化「:的getaddrinfo:產品名稱或服務不知道從/usr/lib/ruby/1.8/(SocketError) \t net/http.rb:564:在'open'中 \t from /usr/lib/ruby/1.8/net/http.rb:564:in'connect' \t from /usr/lib/ruby/1.8/timeout。 RB:48:在'超時」 \t來回m /usr/lib/ruby/1.8/timeout.rb:76:in'timeout' \t from /usr/lib/ruby/1.8/net/http.rb:564:in'connect' –
@Liam,getaddrinfo當您的腳本無法連接到互聯網時發生錯誤。你是否在代理服務器後面運行?也看看:http://stackoverflow.com/questions/2608331/net-http-rb560in-initialize-getaddrinfo-name-or-service-not-known-sockete – Sam
通過工作網絡,我認爲它是一個代理 - 我想我會在家中去。 –