我正在使用此代码从 URL groovy 获取 JSON 对象:当我在浏览器中尝试它时效果很好但是当我在我的程序中使用 httpbuider 尝试它时出现意外错误:403:禁止(意味着它不是关键api,但我把它
有人知道有什么问题吗?
我的代码是:
def getJson(Integer id){
def adress = new HTTPBuilder("https://api.XXXY.com")
def path="/vls/v1/etudiants/${id}?b=my&apiKey=99990"
//Get request
adresseServeur.request(Method.GET, JSON) {
uri.path = path
headers.Accept = 'application/json'
// success response handler
response.success = { resp, json ->
retourJson = json
}
// failure response handler
response.failure = { resp ->
println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
}