【发布时间】:2019-03-02 09:44:46
【问题描述】:
我正在使用插件io.github.http-builder-ng.http-plugin 拨打Http Post。下面是我的build.gradle
plugins {
id "io.github.http-builder-ng.http-plugin" version "0.1.1"
}
import groovyx.net.http.HttpBuilder
task makeRESTCall () {
onlyIf {
!dependencyList.empty
}
doFirst {
println dependencyList
def http = HttpBuilder.configure {
request.uri = 'http://localhost:8080'
request.contentType = 'application/json'
request.uri.path = '/api/v1/fosscomponents/bulkvalidate'
}
http.post {
request.body=dependencyList
response.success {
println "Success"
}
}
}
}
这是我在request.body 中发送的dependencyList 参数
[
{
"groupId":"org.hibernate",
"artifactId":"hibernate-validator",
"version":"5.3.6.Final"
},
{
"groupId":"org.projectlombok",
"artifactId":"lombok",
"version":"1.16.22"
},
{
"groupId":"io.springfox",
"artifactId":"springfox-swagger-ui",
"version":"2.8.0"
}
]
我的后端 API 中的 java 代码(用 Spring Boot 编写)只是以这种格式打印
incomingLists.stream().forEach(
obj -> System.out.println(obj.getGroupId()+" **** "+obj.getArtifactId()+" **** "+obj.getVersion())
);
当我从邮递员那里点击这个 API 时,响应是正确的 - 请参阅下面的代码打印
org.hibernate **** hibernate-validator **** 5.3.6.Final
org.projectlombok **** lombok **** 1.16.22
而当我从我的 gradle 任务中访问相同的 API 时,我的 java 代码会以这种方式打印它..
null **** null **** null
null **** null **** null
不知道是否遗漏了什么
【问题讨论】:
标签: spring-boot gradle groovy build.gradle