-
-
Save masanobuimai/619282 to your computer and use it in GitHub Desktop.
This file contains 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
// g100pon #80 HTTP GET/POST | |
// HTTP GET | |
"http://www.google.com".toURL().eachLine { | |
println it | |
} | |
def qs = [] | |
qs << "q=" + URLEncoder.encode("Groovy 日本語") | |
qs << "hl=" + URLEncoder.encode("ja") | |
println "http://search.yahoo.co.jp/search?${qs.join('&')}".toURL().text | |
/* grape で http-builder を入手するには、$HOME/.groovy/grapeConfig.xml を | |
こんな内容にしておかないとダメだと思う。 | |
<?xml version="1.0" encoding="utf-8"?> | |
<ivysettings> | |
<settings defaultResolver="downloadGrapes" /> | |
<resolvers> | |
<chain name="downloadGrapes"> | |
<filesystem name="cachedGrapes"> | |
<ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml" /> | |
<artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]" /> | |
</filesystem> | |
<ibiblio name="codehaus" root="http://repository.codehaus.org/" m2compatible="true" /> | |
<ibiblio name="codehaus.snapshots" root="http://snapshots.repository.codehaus.org/" m2compatible="true" /> | |
<ibiblio name="ibiblio" m2compatible="true" /> | |
<ibiblio name="java.net2" root="http://download.java.net/maven/2/" m2compatible="true" /> | |
</chain> | |
</resolvers> | |
</ivysettings> | |
*/ | |
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0' ) | |
def http = new groovyx.net.http.HTTPBuilder('http://groovyconsole.appspot.com/') | |
http.post( path: 'executor.groovy', body: [script:'print "Hello World"'], | |
requestContentType: groovyx.net.http.ContentType.URLENC ) { resp, json -> | |
println "output: ${json.outputText}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment