我有一个带有 RestBuilder 的代码,它需要连接到另一个应用程序,目标端点在签名中有一个带有属性的对象。问题是请求返回 404。我如何解决这个问题?我尝试使用 x-www-form-urlencoded (不起作用)
请求方法:
RestResponse restResponse;
String parameters = '{"qtdThreads":3,"channel":"http://localhost:8081/application2"}'
try {
restResponse = new RestBuilder().post("http://localhost:8080/application/endPoint", {
accept("application/json")
contentType "application/json; utf-8"
body(parameters.getBytes("UTF-8"))
connectTimeout: 1000
})
} catch (Exception e) {
e.printStackTrace();
} finally {
return restResponse;
}
目标端点:
Object endPoint(ObjectCommand command) {
render(status: HttpStatus.OK)
}
签名上使用的对象
import grails.validation.Validateable
@Validateable
class ObjectCommand {
URL channel
Integer qtdThreads
static constraints = {
qtdThreads(validator: { Integer val ->
if (!val || val <= 0) {
return "message1"
}
})
channel(validator: { URL val ->
if (!val) {
return "message2"
}
})
}
}