我正在努力解决CORS问题。我从js向不同的域发出请求,该方法允许跨域请求,所有工作都可以正常使用 GET 但不能使用 POST 请求。在 POST 之前调用 OPTIONS 方法并返回标准错误
PdfReader reader = new PdfReader(yourInputstream);
PdfTextExtractor extractor = new PdfTextExtractor(reader);
int pagenumber = reader.getNumberOfPages();
for(int i = 1; i<= pagenumber; i++) {
System.out.println("============PAGE NUMBER " + i + "=============" );
String line = extractor.getTextFromPage(i);
System.out.println(line);
}
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
在客户端,我使用angularjs
return Response.ok().entity(c).header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS")
.header("Access-Control-Allow-Headers", "Content-Type, x-xsrf-token, X-Requested-With, Accept, Expires, Last-Modified, Cache-Control").build();
但也试过
$http.post(url, data).success(...)
同样的结果。我还可以做些什么来修复 POST 请求?
答案 0 :(得分:0)
将以下代码添加到Angular JS应用程序配置文件
$ httpProvider.defaults.useXDomain = true;
删除$ httpProvider.defaults.headers.common [&#39; X-Requested-With&#39;];