I'm trying to send a simple POST request to the push-woosh remote API to create a push notification. (code is in coffee, I'm building an app using Ionic Framework)
@sendPushMessage = ->
pushMessage =
{
"request": {
"application": PW_APP_ID,
"auth": API_TOKEN,
"notifications": [{
"send_date": "now",
"ignore_user_timezone": true,
"content": "message",
"platforms": [1]
}]
}
};
formattedPM = JSON.stringify(pushMessage)
console.log("JSON sent :"+formattedPM)
$http.post(createUrl, formattedPM).success((data, status, headers, config) ->
console.log("success")
return
).error (data, status, headers, config) ->
console.log("failure")
return
The problem is that it returns a bad request error 400. It gets the OPTIONS but it never posts the data. I tried to post the exact same data with Postman and it worked gracefully. So here I am wondering why it doesn't work in Chrome.
I also tried to whitelist the domain in the app config, in vain.
Can somebody help me out ?
Thanks
I added this to my angular config and it now works.
app.config(['$httpProvider', function ($httpProvider) {
//Reset headers to avoid OPTIONS request (aka preflight)
$httpProvider.defaults.headers.common = {};
$httpProvider.defaults.headers.post = {};
$httpProvider.defaults.headers.put = {};
$httpProvider.defaults.headers.patch = {};
}]);