Groovy built-in REST/HTTP client?

前端 未结 7 974
迷失自我
迷失自我 2020-11-28 19:51

I heard that Groovy has a built-in REST/HTTP client. The only library I can find is HttpBuilder, is this it?

Basically I\'m looking for a way to do

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 20:12

    import groovyx.net.http.HTTPBuilder;
    
    public class HttpclassgetrRoles {
         static void main(String[] args){
             def baseUrl = new URL('http://test.city.com/api/Cirtxyz/GetUser')
    
             HttpURLConnection connection = (HttpURLConnection) baseUrl.openConnection();
             connection.addRequestProperty("Accept", "application/json")
             connection.with {
               doOutput = true
               requestMethod = 'GET'
               println content.text
             }
    
         }
    }
    

提交回复
热议问题