Vuecli front-end cross-domain problem solving

Front-end cross-domain problem solving

The best solution for cross-domain is to let the backend solve it, and the frontend can only set up a local proxy

But if the backend says: I have set up to allow cross-domain, how can you cross-domain... If the backend says that he has set up cross-domain issues, we think it is a front-end problem, we must not bury yourself in the problem

The backend may throw the following queries:

Question 1

I can clearly access normally in this postman, why do you cross domains?

        To understand what is cross-domain, cross-domain refers to the http request initiated when the current resource accesses other resources. For security reasons (due to the same-origin policy, domain name, protocol. As long as there is a difference in the port, the source is different), the browser restricts Normal access to these requests, especially note that these occur in the browser. When the interface is called through tools such as postman, only one resource is simply accessed, and there is no mutual access of resources. It's not that postman's normal browser is normal.

Question 2

Backend: Look at me, this is all * (I will give you a screenshot of a bunch of incomprehensible backend codes), which allows all of them to be accessed

        1. If there is no response header, you can try other Ajax request methods first. For example, I tried the request method of uniapp which is also cross-domain.

       2. Check the response headers, if the attribute is repeated, there will be problems too . Below are the response headers under normal circumstances

         3. When initiating a post request, the code will be sent more than once, and an options request will be sent first, so be careful not to add it repeatedly, otherwise the problem will not be solved

Question 3: You did not report cross-domain for other interfaces, why did you report cross-domain for this interface?

        It is estimated that this interface reports an error, and the browser will also parse out the cross-domain error report. First go to postman to see if there is an error like 500

Question 4: I have already configured everything here, but you still report an error like this. My interface is normal for others, and they do not cross domains.

        If everyone else is normal, then don't blame the backend and see why. Note that if it is an HTTPS domain name, it cannot access the api interface of http, otherwise an error will be reported. Also pay attention to whether the api request interface is HTTPS or http.

Don’t look at what the front-end agent says, don’t let the back-end idle

Guess you like

Origin blog.csdn.net/qq_35946021/article/details/127996879