小编Chr*_*say的帖子

使用Groovy的HTTPBuilder发布JSON数据

我发现这个文档就如何发布使用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)

我错过了什么?我非常感谢你能做的任何帮助.

groovy post json nullpointerexception httpbuilder

13
推荐指数
2
解决办法
5万
查看次数

标签 统计

groovy ×1

httpbuilder ×1

json ×1

nullpointerexception ×1

post ×1