Ruby TeamCity api返回json示例
我正在努力从JSON中的team city api中获取结果Ruby TeamCity api返回json示例,ruby,curl,teamcity,curb,Ruby,Curl,Teamcity,Curb,我正在努力从JSON中的team city api中获取结果 require 'open-uri' url = ".../app/rest/buildQueue/" c = Curl::Easy.new(url) do |curl| curl.headers["Content-type"] = "application/json" curl.http_auth_types = :basic curl.username = 'user' curl.pass
require 'open-uri'
url = ".../app/rest/buildQueue/"
c = Curl::Easy.new(url) do |curl|
curl.headers["Content-type"] = "application/json"
curl.http_auth_types = :basic
curl.username = 'user'
curl.password = 'password'
end
c.perform
puts c.body_str
我得到一堆xml文本您需要使用
Accept
标题来控制响应类型:
e、 g(命令行)
curl--urlhttp://xxx/app/rest/buildQueue/ -H接受:“应用程序/json”
您也可以使用“net/http”
require 'net/http'
require 'uri'
url = URI('http://localhost:8111/httpAuth/app/rest/agents')
req = Net::HTTP::Get.new(url)
req['Accept'] = 'application/json'
req.basic_auth 'admin', 'admin'
res = Net::HTTP.start(url.hostname, url.port) {|http|
http.request(req)
}
puts res.body