POST with HTTPBuilder -> NullPointerException?
Posted
by Stefan Kendall
on Stack Overflow
See other posts from Stack Overflow
or by Stefan Kendall
Published on 2010-05-12T23:51:55Z
Indexed on
2010/05/12
23:54 UTC
Read the original article
Hit count: 361
I'm trying to make a simple HTTP POST request, and I have no idea why the following is failing. I tried following the examples here, and I don't see where I'm going wrong.
Exception
java.lang.NullPointerException
at groovyx.net.http.HTTPBuilder$RequestConfigDelegate.setBody(HTTPBuilder.java:1131)
...
Code
def List<String> search(String query, int maxResults)
{
def http = new HTTPBuilder("mywebsite")
http.request(POST) {
uri.path = '/search/'
body = [string1: "", query: "test"]
requestContentType = URLENC
headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
response.success = { resp, InputStreamReader reader ->
assert resp.statusLine.statusCode == 200
String data = reader.readLines().join()
println data
}
}
[]
}
© Stack Overflow or respective owner