httpbuilder

Groovy HTTPBuilder : Getting the entity content from a GZIPed Chunked response

二次信任 提交于 2019-12-21 12:12:57
问题 I need to send a POST request to a web server and be able to read the response sent by said server. I tried using the HTTPBuilder lib with this code : def http = new HTTPBuilder('http://myServer/') http.setProxy("Proxy_IP", 8080, "http") postBody = [cmd:'e',format:'sep',c:'a',b:'b',t:'u',r:'r',kl:'lop'] http.post( body: postBody, requestContentType: URLENC ){ resp -> HttpEntity he = resp.getEntity() println "${resp.getAllHeaders()}" println he.getContentType() println "${resp.getEntity()

Groovy built-in REST/HTTP client?

£可爱£侵袭症+ 提交于 2019-12-17 08:09:28
问题 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 HTTP GETs from inside Groovy code without having to import any libraries (if at all possible). But since this module doesn't appear to be a part of core Groovy I'm not sure if I have the right lib here. 回答1: Native Groovy GET and POST // GET def get = new URL("https://httpbin.org/get").openConnection(); def getRC = get.getResponseCode(); println

httpbuilder and apache.poi.workbook maven problems

时光总嘲笑我的痴心妄想 提交于 2019-12-13 03:48:40
问题 In Maven POM file I have the following: <dependency> <groupId>org.codehaus.groovy.modules.http-builder</groupId> <artifactId>http-builder</artifactId> <version>0.7.1</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.2</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.4.5</version> </dependency> <dependency> <groupId>org.apache.poi<

How to specify content type in request in groovy?

让人想犯罪 __ 提交于 2019-12-12 09:59:36
问题 i'm trying to use the groovy httpbuilder to make a post to the microsoft exchange webservice (EWS). My problem is, I'm unable to set the proper request content-type. The library seems to have its own mind here. Does anyone have an idea? Cheers, Stephan Here is my code: url = "http://exchangeserver/ews/Exchange.asmx" p_body = "<soap request >..."; p_contentType = "text/xml; charset=utf-8" customHeaders = ["SOAPAction":"LONG_URL"] def http = new HTTPBuilder(url); http.auth.basic(authMap

Grails: HTTPBuilder stopped working suddenly

回眸只為那壹抹淺笑 提交于 2019-12-12 02:57:57
问题 Did not upgrade anything, nothing should have changed, but I may have a silly problem I describe here: Grails: refresh dependencies HTTPBuilder now gives this error when I try to def http = new HTTPBuilder( 'http://google.com/' ) UPDATE: I had the wrong error before, this is the error I'm getting when calling that code above in bootstrap.groovy. | Error 2012-03-25 22:50:03,433 [Thread-11] ERROR context.GrailsContextLoader - Error executing bootstraps: java.lang.NoSuchMethodError: org.apache

Grails controller: how render image from byte array

时光怂恿深爱的人放手 提交于 2019-12-12 02:22:38
问题 I have byte array byteImg but I want render in my controller jpeg from byte array: def getSelfie = new HTTPBuilder() getSelfie.request(fullSelfieUrl, GET, JSON) { req -> headers.'X-DreamFactory-Session-Token' = session_id headers.'X-DreamFactory-Application-Name' = 'checkReg' response.success = { resp, reader -> assert resp.statusLine.statusCode == 200 println "Get response: ${resp.statusLine}" println "Content-Type: ${resp.headers.'Content-Type'}" resp = reader as grails.converters.JSON

How to use HTTPBuilder behind a proxy with authentication

蓝咒 提交于 2019-12-11 01:34:55
问题 I tried 2 hours and could not make it work. This is what I did: grails add-proxy myproxy "--host=<host>" "--port=<port>" "--username=<username>" "--password=<psw>" grails use-proxy myproxy I got connection refused error which mean the proxy is not working In my groovy file, I add the proxy def http = new HTTPBuilder("http://http://headers.jsontest.com/") http.setProxy(host, port, "http"); http.request(Method.GET, JSON) { uri.path = '/' response.success = { resp, json -> ..... } } I then get

Groovy HTTPBuilder Mocking the Client

无人久伴 提交于 2019-12-10 10:03:55
问题 This question is closely related to this question. The difference is that I'd like to follow the recommended approach of mocking the client. So, I have the following HTTPBuilder defined: protected readUrl() { def http = new HTTPBuilder("http://example.com") def status = http.request(Method.GET, ContentType.JSON) {req -> response.success = {resp, json -> result = json.toString() new Success<String>(result) } response.'401' = {resp -> final String errMsg = "Not Authorized" new Failed(Failable

HTTPBuilder and MultipartEntity / multipart form-data in Groovy

谁说胖子不能爱 提交于 2019-12-07 04:25:05
问题 Trying to simulate a HTTP POST that needs to combine some INPUT/TEXT fields along with data from a file. It looks like I can have one or the other, but not both? In the snippet below, paramsToPost = [name: 'John', age:22] @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0') Boolean doHttpPost(String url, Map paramsToPost, String fileContent) { HTTPBuilder http = new HTTPBuilder(url) def resp = http.request(Method.POST ) { req -> MultipartEntity mpe =

How to specify content type in request in groovy?

依然范特西╮ 提交于 2019-12-06 10:06:05
i'm trying to use the groovy httpbuilder to make a post to the microsoft exchange webservice (EWS). My problem is, I'm unable to set the proper request content-type. The library seems to have its own mind here. Does anyone have an idea? Cheers, Stephan Here is my code: url = "http://exchangeserver/ews/Exchange.asmx" p_body = "<soap request >..."; p_contentType = "text/xml; charset=utf-8" customHeaders = ["SOAPAction":"LONG_URL"] def http = new HTTPBuilder(url); http.auth.basic(authMap.username, authMap.password) // contentType: p_contentType, http.request( POST ) { contentType = ContentType