我有一系列相当大的条目数组要发布到远程Jira实例的自定义字段中,所以我尝试在Ruby下使用Curb (因为他们的API不允许这样做,而在SQL下这有点危险)。我对其他建议持开放态度,但我终生无法弄清楚如何使用初始get请求设置cookie,然后为post提供参数和适当的头文件
c = Curl::Easy.new("http://jira/secure/Dashboard.jspa")
c.verbose = true
c.http_auth_types = :basic
c.username = 'user'
c.password = 'pass'
c.perform
c.headers="X-Atlassian-Token: no-check"
params= {:fieldConfigId=>'13499',:selectedParentOptionId=>'',:addSelectValue=>'true',:os_username=>'user',:os_password=>'pass',:addValue=>'Barry the Badger',:add=>'Add'}
url="http://jira/secure/admin/EditCustomFieldOptions!add.jspa"
c.http_post(url,params)
c.perform看起来它仍然使用我尝试使用rest_client的同一个URL,但这似乎是cookie的错误行为,我确实需要为atlassian令牌设置上面的头(这样它就不需要用户名/密码)谁有任何想法-或者建议有什么更好的机制来做这件事-或者更好的-我做错了什么;)干杯斯科特
发布于 2012-04-04 06:29:57
排序它移动了所有的东西,并且必须显式地设置enable_cookies (这有点疯狂)
c = Curl::Easy.new
#set first url
c.url = dashboard
#c.verbose = true
c.http_auth_types = :basic
c.username = username
c.password = password
c.enable_cookies = true
c.headers="X-Atlassian-Token: no-check"
#perform login to first link
c.perform
#puts c.cookies
#prepare url to access websudo
c.url=websudo
c.verbose = true
#set password for websudo form
params={:webSudoPassword=>password}.to_query
#set post
c.http_post(c.url,params)
#prepare all variables for creating new custom field option
params={:fieldConfigId=>cf_config:selectedParentOptionId=>'',:addSelectValue=>'true',:os_username=>username,:os_password=>password,:addValue=>cf_value,:add=>'Add'}.to_query
c.url=addoption
c.verbose = true
c.http_post(c.url,params)现在很不错了,我听从了Pass GET parameters with Ruby Curb的建议,使用了ActiveSupport to_query
https://stackoverflow.com/questions/9986606
复制相似问题