问题现象:IOS11,IOS12手机POST方法,发起的option请求之后,返回的status为0,客户端就不再发起POST请求了,导致无法拉取到数据,高版本的IOS手机和android手机都是OK的,服务器也做了跨域设置如下:
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods '*';
add_header Access-Control-Allow-Headers '*';
最后定位问题就是
add_header Access-Control-Allow-Headers '*';
允许所有头部类型没有生效导致的,我们使用的是openresty后端,参考网上的文章,在OPTION里做了如下过滤,也算是做了一个低版本的兼容。
改之前:
location / {
if ($request_method = 'OPTIONS') {
return 204;
}
limit_req zone=one burst=60 nodelay;
content_by_lua_file ./../app/main.lua;
}
改之后:
location / {
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin $http_origin always;
add_header Access-Control-Allow-Credentials true always;
add_header Access-Control-Allow-Methods 'GET,POST,PUT,DELETE,OPTIONS' always;
add_header Access-Control-Allow-Headers 'Authorization,X-Requested-With,Content-Type,Origin,Accept' always;
add_header Access-Control-Max-Age 3600;
add_header Content-Length 0;
return 204;
}
limit_req zone=one burst=60 nodelay;
content_by_lua_file ./../app/main.lua;
}