我找到了这篇关于如何使用 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
}
}
现在我的问题是,我遇到了一个例外
java.lang.NullPointerException
at groovyx.net.http.HTTPBuilder$RequestConfigDelegate.setBody(HTTPBuilder.java:1131)
我错过了什么?我将非常感谢您能提供的任何帮助。