我一直在服务器上的图像上传困难.我正在使用
ngFileUpload在前端.但我总是得到
“对预检要求的响应不通过访问控制检查:请求资源上不存在”Access-Control-Allow-Origin“头”
var uploadFile = function (file) { if (file) { if (!file.$error) { Upload.upload({ url: baseUrl+'upload',file: file }).progress(function (evt) { var progressPercentage = parseInt(100.0 * evt.loaded / evt.total); //console.log(evt.total); }).success(function (data,status,headers,config) { $timeout(function() { console.log(data); console.log(status); if(status==200) { logo_path = data.logo_path; } }); }); } } };
在Laravel我已经配置了这样的CORS:
public function handle($request,Closure $next) { header("Access-Control-Allow-Origin: http://localhost:8001/"); // ALLOW OPTIONS METHOD $headers = [ 'Access-Control-Allow-Methods'=> 'POST,GET,OPTIONS,PUT,DELETE','Access-Control-Allow-Headers'=> 'Content-Type,X-Auth-Token,Origin' ]; if($request->getMethod() == "OPTIONS") { // The client-side application can set only headers allowed in Access-Control-Allow-Headers return Response::make('OK',200,$headers); } $response = $next($request); foreach($headers as $key => $value) $response->header($key,$value); return $response; }
正常跨域POST请求工作正常.即$http.post().我已经尝试了许多不同的标题变体,但没有帮助.此外,OPTIONS请求返回200 OK,但仍显示预检反应失败消息.任何人都可以帮助我如何进一步调试这个问题?