背景:
使用GCDWebServer 搭建的本地http 服务器,用webview 调用接口时总是返回 {isTrusted: true}
原因:
触发跨域访问了,请求被禁止了
解决方法:
[response setValue:@"null" forAdditionalHeader:@"Access-Control-Allow-Origin"];
[response setValue:@"POST" forAdditionalHeader:@"Access-Control-Allow-Methods"];
[response setValue:@"Origin, Authorization, Content-Type, Content-Range, Content-Disposition, Content-Description, X-Requested-With, X-ACCESS_TOKEN" forAdditionalHeader:@"Access-Control-Allow-Headers"];
设置Access-Control-Allow-Origin 允许跨域,里面的值是目标域名,如果是页面填null, 其他服务器同理,设置跨域即可