HTTP - OPTIONS Request Method

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.

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


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap