How to handle HTTP OPTIONS requests in Spring Boot?

Option 1: Spring Boot properties (Spring Boot 1.3.0+ only) Starting with Spring Boot 1.3.0 this behavior can be configured using following property: spring.mvc.dispatch-options-request=true Option 2: Custom DispatcherServlet DispatcherServlet in Spring Boot is defined by DispatcherServletAutoConfiguration. You can create your own DispatcherServlet bean somewhere in your configuration classes, which will be used instead of the one … Read more

How to handle HTTP OPTIONS with Spring MVC?

I added some more detail to the Bozho answer for beginners. Sometimes it is useful to let the Spring Controller manage the OPTIONS request (for example to set the correct “Access-Control-Allow-*” header to serve an AJAX call). However, if you try the common practice @Controller public class MyController { @RequestMapping(method = RequestMethod.OPTIONS, value=”/**”) public void … Read more

HTTP OPTIONS error in Phil Sturgeon’s Codeigniter Restserver and Backbone.js

I encountered exactly the same problem. To solve it I have a MY_REST_Controller.php in core and all my REST API controllers use it as a base class. I simply added a constructor like this to handle OPTIONS requests. function __construct() { header(‘Access-Control-Allow-Origin: *’); header(“Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method”); header(“Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, … Read more

Why am I getting an OPTIONS request instead of a GET request?

According to MDN, Preflighted requests Unlike simple requests (discussed above), “preflighted” requests first send an HTTP OPTIONS request header to the resource on the other domain, in order to determine whether the actual request is safe to send. Cross-site requests are preflighted like this since they may have implications to user data. In particular, a … Read more