HTTP - OPTIONS Request Method

> (World Wide) Web - (W3|WWW) > (HTTP|HTTPS) - Hypertext Transfer Protocol

1 - About

OPTIONS is a request method used in CORS procedure (ie the the "pre-flight” request) asking the server for the CORS headers, but without data.

Advertising

3 - Example

// The content type is important to see the options request
fetch('https://jsfiddle.net/echo/jsonp/?data=nico', {
    mode: 'cors',
    headers: {
      'content-type': 'application/json'
    }
  })

  • Open the devtool, you should see on the console, the following error.
Access to fetch at 'https://jsfiddle.net/echo/jsonp/?data=nico' from origin 'https://gerardnico.com' 
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. 
If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
  • And in the network tab, you should see the OPTIONS request.

chrome_options_request.jpg

web/http/options.txt · Last modified: 2019/03/17 20:38 by gerardnico