class Owner {
static void main(String[] args) {
File file = new File('/Users/huleiwind/Downloads/app.txt')
file.eachLine {
def http = new HTTPBuilder("https://zappinfo.alipay.com")
http.request(GET, JSON) { req ->
headers.'User-Agent' = 'Mozilla/5.0'
uri.path = '/rest/app/queryBasic.json'
uri.query = [appName: it]
//请求成功
response.success = { resp, reader ->
assert resp.statusLine.statusCode == 200
println("${it} ${reader.app.owner.nickName} ${reader.app.bakOwner?.nickName}")
}
//404
response.'404' = { resp ->
println 'Not found'
}
// 401
http.handler.'401' = { resp ->
println "Access denied"
}
//其他错误,不实现则采用缺省的:抛出异常。
http.handler.failure = { resp ->
println "Unexpected failure: ${resp.statusLine}"
}
}
}
}
}
groovy之json请求处理
最新推荐文章于 2024-04-08 19:03:46 发布