3
我想寫一個Ruby腳本在圖片庫網站Piwigo上使用API,這需要您首先登錄一個HTTP帖子並上傳一個圖片與另一個帖子。Ruby HTTP會話cookie
這是我到目前爲止,但它不起作用,只是返回一個401錯誤,任何人都可以看到我要去哪裏錯了?
require 'net/http'
require 'pp'
http = Net::HTTP.new('mydomain.com',80)
path = '/piwigo/ws.php'
data = 'method=pwg.session.login&username=admin&password=password'
resp, data = http.post(path, data, {})
if (resp.code == '200')
cookie = resp.response['set-cookie']
data = 'method=pwg.images.addSimple&image=image.jpg&category=7'
headers = { "Cookie" => cookie }
resp, data = http.post(path, data, headers)
puts resp.code
puts resp.message
end
在運行時給出這個響應;
$ ruby piwigo.rb
401
Unauthorized
有自己的API頁面上一個Perl的例子,我想轉換到Ruby http://piwigo.org/doc/doku.php?id=dev:webapi:pwg.images.addsimple
謝謝我會看看,我認爲更多的驅動網頁比訪問Web API,但? –
你是對的,但正確的API不使用cookies。 – Yossi