【发布时间】:2019-08-25 19:35:21
【问题描述】:
我有一个服务方法,我需要通过请求负载(即正文)使用 HTTP PUT 请求通过字符串属性将 UUID 传递给服务。
Java Spring Boot API 控制器方法的签名是
@PutMapping("group/{groupId}/updateFile")
public String deleteAgencyFile(@PathVariable("groupId") UUID reportId,@RequestBody UUID fileId) {
// Internal Operations - TODO
return 'SUCCESS';
}
Angular HTTP PUT 代码:
updateGroupFile() {
const groupId: string = 'b9ddab47-56a2-11e9-8882-484d7ee28bcd';
const fileId: string = 'c0822353-56a2-11e9-8882-484d7ee28bcd';
const filePath = `http://localhost:3000/api/group/${groupId}/updateFile`
return this.http.put<SimpleResponse>(filePath, fileId);
}
一旦我订阅了 Angular 方法,我就会收到错误消息:
{
"timestamp":"2019-04-04T06:30:32.098+0000",
"status":400,
"error":"Bad Request",
"message":"JSON parse error: Unrecognized token 'c0822353': was expecting 'null', 'true', 'false' or NaN; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'c0822353': was expecting 'null', 'true', 'false' or NaN\n at [Source: (PushbackInputStream); line: 1, column: 10]",
"path":"/api/group/b9ddab47-56a2-11e9-8882-484d7ee28bcd/updateFile"
}
我在 POSTMAN 中尝试了同样的方法,它可以工作,但在 Angular 应用程序中它失败了。
【问题讨论】:
标签: javascript angular spring-boot angular-httpclient http-put