AngularJS对PUT的无效CORS请求 [英] Invalid CORS request for PUT with AngularJS

查看:71
本文介绍了AngularJS对PUT的无效CORS请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Spring应用程序中有一个映射,如下所示:

I have a mapping in my Spring application that looks like this:

@PutMapping(path="/test/{id}")
public @ResponseBody Shop putTest(@PathVariable("id") long id,
                                  @RequestBody User user {
....

尝试通过以下方式使用Angular调用此终结点时:

When trying to call this endpoint with Angular by doing:

$http({
   method: 'PUT',
   url: 'https://localhost:8000/api/test',
   data: senddata,
   params:{'id':id},
   headers: {
     "Content-Type": "application/json; charset=utf-8"
   }
})

我的请求是否有问题,如果可以,该如何解决?

Is there something wrong with my request, if so how can I fix it?

推荐答案

您的后端必须知道请求来自何处. 只是为了测试该请求,您可以指定请求的来源,只需添加该注释即可.

your backend have to know of where requests come. just for you test that request, you can expecific where the request cane from, just add that anotation.

@CrossOrigin(origins = "http://localhost:9000")
@PutMapping(path="/test/{id}")
public @ResponseBody Shop putTest(@PathVariable("id") long id,
                                  @RequestBody User user {
....

我希望它有用

这篇关于AngularJS对PUT的无效CORS请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆