简体   繁体   中英

Cross-domain request to subdomain

I have front-end part (js) on http://example.com and back-end (REST API) on http://api.example.com . Is it possible to make requests to back-end without OPTIONS request before each GET/POST etc request?

You cannot get rid of the OPTIONS request unleess you don't send any data, and don't send custom headers.

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

The OPTIONS request will be made if you send data with Content-Type other than application/x-www-form-urlencoded, multipart/form-data, or text/plain.

Also, as stated there, the OPTIONS request will be made if you send custom headers.

So in order to avoide the preflight, you'll be forced to NOT do any of those things.

This is all because the idea is to first check if it the CORS will be allowed or not and you don't send any data to a server that you don't want to send.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM