This will be long:
Ok, so I'm developing a Google Calendar gadget that sends requests to the Python webapp2 REST api hosted by the Google App Engine.
The problem arises when I try to ALMOST something that it does not allow me because of CORS. DevTools Chromes says:
Method: OPTIONS. Status: (failed) Request header field Content-Type is not allowed by Access-Control-Allow-Headers. Origin https://hq34i4geprnp5vci191ljfuhcoerscl4-a-calendar-opensocial.googleusercontent.com is not allowed by Access-Control-Allow-Origin.
I know this is because of CORS. Here:
Ajax - "The origin of the local host is not allowed through Access-Control-Allow-Origin"
It says that I have to add
Access-Control-Allow-Origin: *
In the headers, but again, I'm new to ajax, and I wonder if that was the case:
$.ajax({ type: "POST", url: "https://myapp.appspot.com/service", contentType: "application/json; charset=utf-8", data: data, beforeSend: function (request) { request.setRequestHeader("Access-Control-Allow-Origin", "*"); } success: function(data) { alert("AJAX done"); } });
Adding these headers: is different (which makes me wonder if the origin is allowed, although I really don't know):
Method: OPTIONS. Status: (failed) Request header field Content-Type is not allowed by Access-Control-Allow-Headers. XMLHttpRequest cannot load https://myapp.appspot.com/service. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers.
I even found this:
http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/
Which allows me to make GET requests, but I would like to know how to do it without it.
Also on my web server I have the following:
... class webService(webapp2.RequestHandler): options(self): self.response.write('options') post(self): self.response.write('post') application = webapp2.WSGIApplication([ ('/', MainPage), ('/service', webService) ], debug=True)
I do not know if I should add anything else to the web server, and did not find the information I need. Also, I think I'm close to achieving a CORS request, but I cannot find an example that explains all this.
Please, help.