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