axios cross-domain and request automatic set cookie

Request automatic set-cookie, global default configuration setting method:

axios.defaults.withCredentials=true   默认是false

 

Cross domain configuration, use iis as proxy server

1. Open iis, find the HTTP response header and click it, right-click - add

Access-Control-Allow-Headers   content-type

Access-Control-Allow-Methods   GET,POST,PUT,DELETE,OPTIONS

Access-Control-Allow-Origin       *

As shown in the figure:

2. Add the project to iis, create a new website - then follow the steps

Note: You need to add the host name, and you need to find the hosts file under C:\Windows\System32\drivers\etc, and then add the host name, as shown in the figure

 

 3. Find the Web.config file in the root directory of the added project and configure it

<system.webServer>
     <httpProtocol>
        <customHeaders>
           <remove name="Access-Control-Allow-Origin" />
           <add name="Access-Control-Allow-Origin" value="http://localhost:8888" /> //The running address of the local project
           <add name="Access-Control-Allow-Credentials" value="true" />
         </customHeaders>
      </httpProtocol>
   </system.webServer>

All my configuration:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324768656&siteId=291194637