简体   繁体   English

从 chrome 扩展启动 spring 上的交叉原点

[英]cross origin on spring boot from chrome extension

In my spring application, I have a method:在我的 spring 应用程序中,我有一个方法:

@CrossOrigin(origins="*")
@PostMapping("/datum")
Datum test(@RequestBody String data) {
    return repository.save(new Datum(data));
}

I want that all the application can access it, so I have put that @CrossOrigin(origins="/**") .我希望所有应用程序都可以访问它,所以我放了@CrossOrigin(origins="/**") But when I try to do so, it runs without any complain.但是当我尝试这样做时,它运行时没有任何抱怨。

This is how I'm sending data from a chrome extension:这就是我从 chrome 扩展发送数据的方式:

var request = new XMLHttpRequest();
let url='http://localhost:8080/datum';
let data=JSON.stringify({ "data": body});
request.open('POST', url, true);
request.setRequestHeader("Content-Type", "application/json");
request.send(data);

My extension manifest:我的扩展清单:

"permissions": [
    "activeTab",
    "tabs",
    "<all_urls>",
    "background",
    "http://*/*",
    "https://*/*",
    "http://localhost:8080/datum"
],

Gives me error 403给我错误403

But client still can't access this, how this can be solved?但是客户端仍然无法访问这个,如何解决?

In my @SpringBootApplication annoted class, I added this:在我的@SpringBootApplication注释 class 中,我添加了这个:

@Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**").allowedOrigins("*");
            }
        };
    }

And in manifest.json :manifest.json中:

"permissions": [
    "activeTab",
    "tabs",
    "background",
    "http://*/"
  ]

Now it works.现在它起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Cross Origin Chrome扩展程序 - Cross Origin Chrome Extension 从 Chrome 扩展程序执行跨源请求时存在 XMLHTTPRequest 漏洞? - XMLHTTPRequest vulnerabilities when doing cross origin requests from a Chrome extension? Chrome扩展程序的跨域XMLHttpRequest返回状态0 - Cross-Origin XMLHttpRequest from Chrome Extension Returning Status 0 用于 chrome 扩展的 iFrame 的跨域问题 - Cross-Origin issue with iFrame for chrome extension Chrome扩展程序中的跨域XHR失败 - Cross-Origin XHR failed in Chrome extension Chrome扩展程序的内容脚本中出现XSS“使用访问跨域框架阻止了框架的起源”错误 - XSS “Blocked a frame with origin from accessing a cross-origin frame” error in content script for a Chrome extension 阻止具有原始 chrome-extension 的框架访问跨源框架 - Blocked a frame with origin chrome-extension from accessing a cross-origin frame Chrome 扩展 - 未捕获的 DOMException:阻止具有源的框架访问跨域框架 - Chrome Extension - Uncaught DOMException: Blocked a frame with origin from accessing a cross-origin frame chrome.tabs.executeScript(…)时,Chrome扩展程序存在跨源问题 - Cross origin issue with Chrome extension when chrome.tabs.executeScript(…) 将XHR从Chrome扩展程序发送到PHP页面时出错:仅HTTP支持跨源请求 - Error when sending XHR from Chrome Extension to a PHP page: Cross origin requests are only supported for HTTP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM