간단한 HTTP POST 요청을하려고하는데 다음 이유가 무엇인지 알 수 없습니다. 나는 예제 here을 따라했지만, 나는 어디가 잘못 될지 보지 못했다.POST with HTTPBuilder -> NullPointerException?
예외
java.lang.NullPointerException
at groovyx.net.http.HTTPBuilder$RequestConfigDelegate.setBody(HTTPBuilder.java:1131)
...
코드이 작동
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
}
}
[]
}
이 고정에게 그것은 나를 위해. 'send URLENC, [string1 : "", string2 : "heroes"]'도 사용 가능하지만, HTTPBuilder를 조롱 할 때 유닛 테스트가 더 어려워집니다. –