Why is HttpRequest sending the OPTIONS verb instead of POST? Why is HttpRequest sending the OPTIONS verb instead of POST? dart dart

Why is HttpRequest sending the OPTIONS verb instead of POST?


The OPTIONS verb is a preflight request sent by some browsers to check the validity of cross origin requests. It pretty much checks with the server that the Origin(requester) is allowed to make the request for a specified resource. Also, depending on which headers are sent back by the server it lets the browser know which headers, methods, and resources the origin is allowed to request form the server.

The browser sends the OPTIONS request then if the server answers back with the correct headers (CORS headers) allowing the origin to make the request, you should see your POST request go through afterwards.

Note that the CORS headers must be returned on both the OPTIONS response as well as the POST response. This means your server must be able to respond to the options method on the routes you want to access across domains.

This is known as Cross-origin Resource Sharing. Mozilla has some pretty good documentation on the subject. https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS

If you have more questions let me know and I'll answer them.


One way to avoid this problem is by sending the request payload without custom headers and using formData to setup your request payload.