groovy之json请求处理
发布时间:2020-12-14 16:40:50 所属栏目:大数据 来源:网络整理
导读: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' = 'Moz
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}" } } } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |