I am facing an issue with posting events into a CherryPy small application that responds to GET/POST requests. When attempting to do so using AngularJS, nothing gets posted.
I'm unsure if the problem lies with AngularJS or CherryPy (CP). Cross-domain functionality is enabled in CP, but it seems unable to recognize the POST method. Strangely, the same operation works fine with CURL.
The POST method in CP is defined as follows:
def POST(self, date, description):
# Reading items to capture any server-side updates
events = {
"date": int(date.encode('ascii','ignore')),
"description": description.encode('ascii','ignore'),
"status":"Active"
}
# Storing changes
save_events(events)
return ('Event created\n')
Headers are set up with the following function:
def enableCrossDomain():
cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
cherrypy.response.headers["Access-Control-Allow-Methods"] = "GET, POST"
cherrypy.response.headers["Access-Control-Allow-Headers"] = "Cache-Control, X-Proxy-Authorization, X-Requested-With"
def OPTIONS(self):
enableCrossDomain()
return
A CURL call looks like this:
curl -d $EPOCH_DATE -d $EVENT -X POST 'myurl.com:1234/api/events/'
When trying the same with AngularJS:
var message = "'" + $scope.event_description + "' '" + $scope.datetime_start + "'";
console.log(message);
$scope.post_url = "myurl.com:1234/api/events";
$http.post($scope.post_url,message).success();
I've attempted sending "message" as JSON and specifying it in the headers, but have been unsuccessful. Any suggestions on what I might be missing or what else I could try?