web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="OPTIONSVerbHandler" />
<add name="PHPviaFastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="D:folderserverPHPphp7.3php-cgi.exe" resourceType="Unspecified" />
</handlers>
</system.webServer>
</configuration>
scriptProcessor 的目录地址 可通过 phpinfo.php 获得,后面加上 php-cgi.exe
这里两步
第一步,删除 iis的OPTIONSVerbHandler对options的拦截
第二步,添加对php的解释器,让options也由php进行控制,这样就非常灵活了。
php的入口文件添加
header('Access-Control-Allow-Origin: '. $_SERVER['HTTP_ORIGIN']);//允许跨域请求
header('Access-Control-Allow-Headers: Origin,Token, Referer, user_token, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie');
header('Access-Control-Allow-Credentials: true');//允许跨域请求
header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'OPTIONS') {
exit();
}
看看这个能解决 跳转到 php脚本的问题吗
https://www.zhaokeli.com/article/8542.html
web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="OPTIONSVerbHandler" />
<add name="OPTIONS" path="*" verb="OPTIONS" modules="ProtocolSupportModule" resourceType="Unspecified" />
</handlers>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, DELETE" />
<add name="Access-Control-Allow-Headers" value="ISS,Origin,Token, Referer, user_token, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
遗憾: 没有找到 只处理options的时候,对头文件进行设置。这里设置后,直接跳过了php的options代码检测。
比较完美的方案是 发现是options处理,也放行,给到脚本进行处理。这里要是tomcat或其他中间件,可能就是另一种处理方式了。
参考:https://blog.csdn.net/wanglui1990/article/details/79180887