javascript - AngularJS performs an OPTIONS HTTP request for a cross-origin resource => error 401 -


i'm trying use $resource datas rest web service.

here code :

    return $resource('http://serverurl', {}, {                  getquartiers: {                     method: 'get',                     headers:  {                              'authorization': 'basic base64login:pseudostring',                      },                  },             }); 

the problem headers this, it's option request send , error 401 unauthorized. if remove headers, it's request. need headers send authorization string !

otherwise webservice ok, either going chrome directly url => popup login/pwd => correct datas @ json format or using postman chrome extension, send request.

what's matter ?

you don't seem handling preflight options requests.

your web api needs respond options request in order confirm indeed configured support cors.

to handle this, need send empty response back.

this check added ensure old apis designed accept get , post requests not exploited. imagine sending delete request api designed when verb didn't exist. outcome unpredictable , results might dangerous.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -