我发现这个文档就如何发布使用HttpBuilder JSON数据.我是新手,但这是一个非常简单的例子,很容易理解.这是代码,假设我已导入所有必需的依赖项.
def http = new HTTPBuilder( 'http://example.com/handler.php' )
http.request( POST, JSON ) { req ->
body = [name:'bob', title:'construction worker']
response.success = { resp, json ->
// response handling here
}
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,我得到了一个例外
java.lang.NullPointerException
at groovyx.net.http.HTTPBuilder$RequestConfigDelegate.setBody(HTTPBuilder.java:1131)
Run Code Online (Sandbox Code Playgroud)
我错过了什么?我非常感谢你能做的任何帮助.