我使用lighttpd提供静态内容(html、css 和 js) 。我想使用带有 python 的 wsgi 应用程序从本地主机上托管的服务器调用 api。当我尝试从前端调用 api(使用 ajax 和 jquery 库)时,出现以下错误。

我正在通过勇敢的浏览器访问该网站。出于测试目的,如何禁用此“跨源读取阻止 (CORB) 阻止跨源响应”功能?
我正在使用 React 创建一个 Web 服务。我想加载从 React 应用程序上传到 Google Drive 的图像。但是,我收到跨源读取阻止 (CORB) 错误。我应该怎么办?
我在端口3000上运行带有express的服务器,在端口4200上运行带有angular 7的客户端。发出请求后,遇到了CORS问题。
通过CORS策略已阻止从源“ http:// localhost:4200 ” 访问“ http:// localhost:3000 / drug ” 上的XMLHttpRequest :在请求的资源上不存在“ Access-Control-Allow-Origin”标头。
我已经在线尝试了所有解决方案,例如使用cors软件包,并在路由器之前设置了中间件,如以下代码所示(Angular 6-请求资源上没有'Access-Control-Allow-Origin'标头)。但是它仍然没有解决,并不断出现同样的错误。有人会遇到无法用所有解决方案解决CORS的问题吗?请你帮助我好吗?
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
res.header(
"Access-Control-Allow-Header",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "http://localhost:4200");
res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
res.header(
"Access-Control-Allow-Header",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
Run Code Online (Sandbox Code Playgroud) 警告是:
jquery-1.9.1.js:8526跨域读取阻止(CORB)使用MIME类型application / json 阻止了跨域响应https://www.metaweather.com/api/location/search/?query=lo。有关更多详细信息,请参见https://www.chromestatus.com/feature/5629709824032768。
我的代码是:
<!DOCTYPE html>
<html>
<head>
<title> Search API </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js">
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="container">
<h2>API Search Whether</h2>
<div class="row">
<div class="col-md-6">
<input type="text" name="name" id="name" class="form-control">
</div>
<div class="col-md-2">
<button type="button" id="search" class="btn btn-primary btn-lg">Search</button>
</div>
</div>
<br><br><br><br>
<div class="row">
<table class="table" border="2px">
<thead>
<tr style="color:blue; font-weight:bold;">
<td >Domain</td>
<td>Suffix</td>
<td>Expiry Date</td>
<td>Created At</td>
<td>Country</td>
</tr>
</thead>
<tbody id="tbody">
</tbody> …Run Code Online (Sandbox Code Playgroud) 我有一个模型:
export class Employe {
constructor(public id?: any,
public nom?: String,
public prenom?: String,
public cin?: String){}
}
Run Code Online (Sandbox Code Playgroud)
员工.component.ts
ngOnInit(){
this.loadEmployes();
}
pageEmployes:any={};
loadEmployes():Observable<any>{
this.http.get("http://localhost:8080/api/employe").subscribe(
data=>{
console.log(data);
this.pageEmployes = data;
}, err=>{
console.log(err);
}
);
return this.pageEmployes;
}
Run Code Online (Sandbox Code Playgroud)
员工.component.html
<tr *ngFor="let item of pageEmployes">
<td>{{item.nom}}</td>
<td>{{item.prenom}}</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
协作控制器.java
@RestController
@RequestMapping("/api/employe")
@CrossOrigin("*")
public class CollaborateurController {
@Autowired
private CollaborateurRepository collaborateurRepository;
@RequestMapping(value="", method=RequestMethod.GET)
public List<Collaborateur> getEmp() {
return (List<Collaborateur>) collaborateurRepository.findAll();
}
Run Code Online (Sandbox Code Playgroud)
这引发了我的错误:
ERROR 错误:找不到类型为“object”的不同支持对象“[object Object]”。NgFor 仅支持绑定到可迭代对象,例如数组。
从源“ http://localhost:4200 ”访问“ http://localhost:8080/api/employe ”的XMLHttpRequest已被 CORS …
我正在尝试 从using模式中获取html位于 url 的文件,但响应被 CORB(跨源读取阻塞)阻止。https://sub.app.test/htmlhttps://app.testno-cors
fetch('https://sub.app.test/html', { mode: 'no-cors'})
Run Code Online (Sandbox Code Playgroud)
为什么?
这是我的组件中的方法:
onDelete(s) {
const conf = confirm('etes vous sur');
if (conf) {
console.log(s._links.self.href);
this.catservice.Deleteprod(s._links.self.href).subscribe(data => {console.log(s._links.self.href);
}, error1 => {
console.log(error1);
});
}
}
Run Code Online (Sandbox Code Playgroud)
这是我服务中的方法:
public Deleteprod(url) {
return this.httpClient.delete(url);
}
Run Code Online (Sandbox Code Playgroud)
我想删除这个对象,s._links.self.href所以这url没有错,但是当我尝试websecurityconfig使用她尝试过的方法创建类时遇到了这个问题,@CrossOrigin(origins = "*")但没有解决方案,请帮助我。
这是我的错误:
Access to XMLHttpRequest at 'http://localhost:8080/offres/24' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
rest spring-boot angular cross-origin-read-blocking angular8