我的 Spring 应用程序中有一个映射,如下所示:
@PutMapping(path="/test/{id}")
public @ResponseBody Shop putTest(@PathVariable("id") long id,
@RequestBody User user {
....
当尝试通过 Angular 调用此端点时:
$http({
method: 'PUT',
url: 'https://localhost:8000/api/test',
data: senddata,
params:{'id':id},
headers: {
"Content-Type": "application/json; charset=utf-8"
}
})
我的请求是否有问题,如果有我该如何解决?
你的后端必须知道请求来自哪里。
只是为了您测试该请求,您可以具体说明请求来自哪里,只需添加该注释即可。
@CrossOrigin(origins = "http://localhost:9000")
@PutMapping(path="/test/{id}")
public @ResponseBody Shop putTest(@PathVariable("id") long id,
@RequestBody User user {
....
我希望它有用
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)