我正在尝试将Angular JS 应用程序与后端Spring Boot集成,但是遇到了预检请求不允许重定向的问题。
这是部署在OpenShift上的,我已经通过在控制器方法中添加一些注释来配置启用CORS,从而解决了以下问题:请求没有“Access-Control-Allow-Origin”标头在传入请求中:CORS策略问题。
@CrossOrigin(allowedHeaders = "*", origins = "*", exposedHeaders =
"Access-Control-Allow-Origin", methods = {
RequestMethod.POST, RequestMethod.GET, RequestMethod.PUT,
RequestMethod.DELETE, RequestMethod.HEAD,
RequestMethod.OPTIONS, RequestMethod.PATCH, RequestMethod.TRACE })
@RestController
public class Controller {
@Autowired
Service botService;
@Autowired
Environment env;
@CrossOrigin()
@RequestMapping(value = "/jwtToken", method = {
RequestMethod.POST }, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<UnifiedService> botConntor(
@RequestBody UnifiedInput input, HttpServletRequest request) {
UnifiedBPMService output = botService.processBotRequest(input, request);
return new ResponseEntity<UnifiedService>(output, HttpStatus.OK);
}
实际的Angular应用程序中出现的错误是:
选项调用返回了以下响应:跨域资源共享(CORS)策略阻止从源 'http://' 访问 'http:///chatbot/api/jwtToken' 的XMLHttpRequest,因为预检请求的响应未能通过访问控制检查:预检请求不允许重定向。
Request URL: http://<domain>/chatbot/api/jwtToken
Request Method: OPTIONS
Status Code: 302 Found
Remote Address: 10.235.222.220:80
Referrer Policy: no-referrer-when-downgrade