-1

When I call a web service (using PUT method) from my AngularJS code I got following error in Firebug's console (with exclamation mark at the beginning):

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://52.77.235.82:8080/school/user. (Reason: Did not find method in CORS header 'Access-Control-Allow-Methods').

In Firebug I see the following headers for the request:

Accept          : application/json, text/plain, */*
Accept-Encoding : gzip, deflate
Accept-Language : en-US,en;q=0.5
Content-Length  : 81
Content-Type    : application/json
Host            : 52.77.235.82:8080
Origin          : http://localhost:8080
Referer         : http://localhost:8080/
User-Agent      : Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:44.0) Gecko/20100101 Firefox/44.0
authToken       : eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2IjowLCJkIjp7InVpZCI6IjIiLCJlbWFpbCI6ImFzaGlzaC5wQGV5d2FsYWJzLmNvbSIsInNjaG9vbElkIjoyMH0sImlhdCI6MTQ1NzAwNDE2NH0
.Iw_9DLaqrlkR0hKgtz-sWAfHaRq40CeHk5MM1y7Es9k

Within the Response tab I get nothing.

But at the same time, if I send the request in the expected JSON format from POSTER I get the success response.

This is really surprising. I also checked my AngularJS code to call the respective web service and I found no error in it.

I searched a lot for the solution but unfortunately I couldn't find it. Can someone please provide me the perfect solution for the above issue?

Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132
PHPLover
  • 1
  • 51
  • 158
  • 311

1 Answers1

2

As the error message states, the server needs to respond with an appropriate Access-Control-Allow-Methods header.

I.e., in your case this is:

Access-Control-Allow-Methods: PUT

Detailed information about how to use Cross-Origin Resource Sharing (CORS) can be found at MDN.

Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132