【发布时间】:2020-07-12 19:41:59
【问题描述】:
我正在尝试使用 x-wwww-form-urlencoded 内容类型向我的 Spring Boot 服务发送一个 http 请求,但我不确定我做错了什么。
这是我的角度代码:
img(desc:HTMLInputElement, selectedFile){
let url = "http://localhost:8080/api/v1/upload_image"
const body = new HttpParams()
body.set("image", selectedFile)
body.set("description", desc.value)
return this.http.post<Isecurity[]>(url, body.toString(),{
headers:new HttpHeaders()
.set('Content-Type', 'application/x-www-form-urlencoded')
} )
}
这是我的 Spring 服务:
@PostMapping("upload_image")
@CrossOrigin
public Map<String, Boolean> upload_image(@RequestParam MultipartFile image, @RequestParam String description) {
Map<String, Boolean> values = new HashMap<>();
values.put("response", true);
return values;
}
我收到 500 服务器错误。任何帮助将不胜感激。
【问题讨论】:
-
使用 FormData 发送