Created
May 23, 2013 14:26
-
-
Save nicholashagen/5636470 to your computer and use it in GitHub Desktop.
Groovy HTTPBuilder fails with GitHub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.6' ) | |
import groovyx.net.http.* | |
import groovyx.net.http.RESTClient | |
import static groovyx.net.http.ContentType.URLENC | |
import static groovyx.net.http.ContentType.* | |
import static groovyx.net.http.Method.* | |
// this fails | |
try { | |
def github = new RESTClient( 'https://api.github.com' ) | |
def resp = github.get( path : '/gists/public' ) | |
assert resp.status == 200 | |
assert resp.contentType == JSON.toString() | |
assert ( resp.data instanceof net.sf.json.JSON ) | |
} | |
catch (e) { println e } | |
// this also fails | |
try { | |
def http = new HTTPBuilder('https://api.github.com') | |
http.get( path : '/gists/public', | |
contentType : JSON) { response, reader -> | |
assert resp.status == 200 | |
} | |
} | |
catch (e) { println e } | |
// this works | |
new URL('https://api.github.com/gists/public').text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment