typescript - angular 2 file upload 401 unauthorized (CORS) -


i getting error "401 unauthorized" in chrome , firefox, when uploading files angular 2 cli apache2-server. backend of server in php. i've tried 3 different node modules, behave same. i'm getting error on options-preflight,

"xmlhttprequest cannot load (uploadurl) response preflight has invalid http status code 401".

this error happens, if im requesting source (e.g. "localhost:4200"). when executing project on apache server, upload works fine.

so on localhost: difference is, requests before uploading have cookie in request headers. not upload-request. here's image: headers on upload-request


i've tried theese 3 node modules far:

  • ng2-file-upload
  • angular2-http-file-upload
  • ng2-uploader

"withcredentials" on uploader (e.g. ng2-file-upload valor software ng-2-file-upload) set true. tried setting header x-requested-with: 'xmlhttprequest'. , tried setting authorization: basic-header....still same issue. when setting cookie:-header myself onbeforefileupload, of course error message

"refused set unsafe header cookie"

would cool, if knows how fix this. looked everywhere answer nothing did help.

edit: theese headers set in php backend:

    header("access-control-allow-origin: http://localhost:4200");     header("access-control-allow-credentials: true");     header("access-control-allow-headers: *");     header('access-control-allow-methods: get, post, options'); 

still got error.

seems server site error.

do have below headers in php files?

header('access-control-allow-origin: *'); header('access-control-allow-methods: get, post'); header("access-control-allow-headers: x-requested-with"); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -