2

I'm struggling with getting results from the team city api in JSON

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

I get a bunch of xml text

Mohammad Nadeem
  • 9,134
  • 14
  • 56
  • 82

2 Answers2

0

You need to use the Accept header to control the response type:

e.g (command line)

curl --url http://xxx/app/rest/buildQueue/ -H Accept:"application/json"

Documentation Reference

SteveChapman
  • 3,051
  • 1
  • 22
  • 37
0

also you can use "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
mimin0
  • 871
  • 8
  • 9