简体   繁体   English

跨域请求到子域

[英]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 . 我在http://example.com上有前端(js),在http://api.example.com上有后端(REST API)。 Is it possible to make requests to back-end without OPTIONS request before each GET/POST etc request? 是否可以在每个GET / POST等请求之前发出没有OPTIONS请求的后端请求?

You cannot get rid of the OPTIONS request unleess you don't send any data, and don't send custom headers. 除非您不发送任何数据,也不发送自定义标头,否则您不能摆脱OPTIONS请求。

According to Why am I getting an OPTIONS request instead of a GET request? 根据为什么我得到一个OPTIONS请求而不是GET请求?

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. 如果您发送的内容类型不是application / x-www-form-urlencoded,multipart / form-data或text / plain,则将发出OPTIONS请求。

Also, as stated there, the OPTIONS request will be made if you send custom headers. 另外,如此处所述,如果您发送自定义标头,则将发出OPTIONS请求。

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. 这就是所有原因,因为其想法是首先检查是否允许CORS,并且您不会将任何数据发送到您不想发送的服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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